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




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;


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

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

    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;


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,


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.


登录 关闭
发送“验证码”获取 | 15天全站免登陆