开发者

UISlider how to set the initial value

开发者 https://www.devze.com 2022-12-31 06:46 出处:网络
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 c开发者_开发

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 c开发者_开发百科ustom control. I was thinking in the cell init

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

i could just call something like

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

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,

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.


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.

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.


PS I had the same issuer - you need to add the UISlide view first then you can change the value.

0

精彩评论

暂无评论...
验证码 换一张
取 消