我刚开始学习,所以请放轻松...
目标是获取选择器中所选行的文本值,并在另一个视图的标签中显示该值。
现在我在存储字符串值时遇到困难,所有内容都会编译并加载,但第二个视图中的标签仍为空白。请取消通知我。
//String taken from selected pickerview line and stored in selectedstring
NSString *string = [NSString stringWithFormat:@"You Selected: %@",[_platforms objectAtIndex:row]];
Selectedstring.text = string;
在“下一个视图”按钮上按:
- (IBAction)NextView:(id)sender {
SecondView *secondview = [[SecondView alloc]init];
self.SecondViewData = secondview;
SecondViewData.passedValue = Selectedstring.text;
[self presentViewController:secondview animated:YES completion:nil];
然后在下一个视图的“viewdidload”区域中:
label.text = passedValue;
答案 0 :(得分:0)
- (void)pickerView:(UIPickerView *)pickerView didSelectRow: (NSInteger)row inComponent:(NSInteger)component {
SecondView *secondview = [[SecondView alloc]init];
self.SecondViewData = secondview;
SecondViewData.passedValue = Selectedstring.text;
[self presentViewController:secondview animated:YES completion:nil];
secondview.label.text = passedValue; //passing values to uilabel
}
答案 1 :(得分:0)
你只需要在ViewWillAppear而不是viewDidLoad中写下面的语句。
label.text = passedValue;
感谢