开发者

Need Help Setting UIPicker's Label From Selection

I have a UIPicker with a UILabel above it that updates displaying the current selection.

When I go to this view the 2nd time, the UIPicker's selection is on the last cell where I left off, but the label is on the default string. How can I make it so the label is also on where I last left off?

This is the code I am using:

- (void)displayPicker
{
    self.numberLabel.text = @"1 number";
}
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component 
{
    self.numberButtonText = [NSString stringWithFormat:@"%@ number", [self.pic开发者_如何学GokerArray objectAtIndex:row]];
    self.numberLabel.text = self.numberButtonText;
}


If i assume correct, you are calling

-(void)displayPicker

to set the default numberLabel text value (as in self.numberLabel.text = @"1 number";).

Possible cause would be, that - (void)displayPicker is called every time, the view is presented to the user, but

- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component

is not.

You might want to check for such behavior, by inserting some NSLog() statements and perhaps correct it by using something like this:

- (void)displayPicker
{
    self.numberLabel.text = [NSString stringWithFormat: @"%i number", 
                            [self.numberPicker selectedRowInComponent: 0 ]];
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜