UISlider如何设置初始值 [英] UISlider how to set the initial value

查看:122
本文介绍了UISlider如何设置初始值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这个iPhone开发人员的东西上我还很新,我正在公司的一些现有代码上工作.我试图设置初始值的uislider实际上在UITableViewCell中,并且是一个自定义控件.我在想单元格初始化

I'm pretty new at this iphone dev stuff and i'm working on some existing code at a company. The uislider i'm trying to set the initial value on is actually in a UITableViewCell and is a custom control. I was thinking in the cell init

cell = (QuantitiesCell *)[self loadCellWithNibName:@"QuantitiesCell" forTableView:ltableView withStyle:UITableViewCellStyleDefault];

我可以打电话给

((QuantitiesCell *)cell).value = 5;

实际的QuantitiesCell类具有成员值和以下函数

The actual QuantitiesCell class has the member value and the following functions

-(void)initCell;{
    if (listOfValues == nil) {
        [self initListOfValues];
    }
    quantitiesSLider.maximumValue = [listOfValues count]-1;
    quantitiesSLider.minimumValue = 0;
    quantitiesSLider.value = self.value;
}

-(void)initListOfValues;{
    listOfValues = [[NSMutableArray alloc] initWithCapacity:10];
    int j =0;
    for (float i = minValue; i <= maxValue+increment; i=i+increment) {
        [listOfValues addObject:[NSNumber numberWithFloat: i]];
        if (i == value) {
            quantitiesSLider.value = j;
        }
        j++;
    }
}

就像我说的那样,我还很陌生,所以如果我需要发布更多代码以显示将获得帮助的内容,请告诉我,

like i said, i'm pretty new at this so if i need to post more of the code to show whats going to get help, let me know,

此滑块始终默认为1,该滑块的范围通常为1-10,我想将其设置为我要编辑的项目的特定值.

This slider always is defaulting to 1, the slider ranges usually from 1-10, and i want to set it to a specific value of the item i'm trying to edit.

推荐答案

如果链接正确(在Interface Builder中进行连接),则设置slide.value是正确的方法.如果您已在代码中创建了UISlider,则只需设置value属性即可.如果这不起作用,则首先要确保对象是活动的"(正确分配,未释放,不在范围内等),其次要确保实际上设置了slider.value的函数被调用.

Setting slider.value is the correct way if your linkage is correct (you have made the connections in Interface Builder). If you have created a UISlider in code, all you have to do is set the value property. If that is not working then be sure firstly that the object is "live" (correctly allocated, not released, not out of scope etc.) and secondly that the functions in which you set slider.value are actually being called.

如果您使用的是Interface Builder,但不确定如何将滑块作为IBOutlet连接,则应查看iTunes University-搜索"CS193P"以查找斯坦福大学的一些出色视频.前几对将带您建立这些联系.如果使用IB而您尚未建立连接-将不会发生任何事情.

If you are using Interface Builder and are not sure of how to connect your slider as an IBOutlet, you should check out iTunes University - search for "CS193P" to find some excellent videos from Stanford University. The first couple will take you through making those connections. If using IB and you have not made the connection - nothing will happen.

这篇关于UISlider如何设置初始值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆