我想使用模型转场。通过单击“年”按钮,它应该转到“年 View Controller ”,单击表格单元格并将屏幕设置为初始 View Controller ,在 View Controller 中设置标签 1。
Person.h
#import <Foundation/Foundation.h>
@interface CarObj : NSObject
@property (nonatomic, strong) NSMutableString *Year;
@property (nonatomic, strong) NSMutableString* Name;
@end
点击名称按钮后,它应该转到名称 View Controller ,点击它应该将单元格的信息保存到 Person.h 的“名称”参数中。
如何实现?我无法设置标签 1 和标签 2....
对于 segue 我正在使用:
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([[segue identifier] isEqualToString:@"GrabYear"])
{
YearViewController *yvc = [segue destinationViewController];
[yvc setCurrentCar:currentCar];
}
}
对于我正在使用的行选择:
MenuViewController *mvc = [self.storyboard instantiateViewControllerWithIdentifier:@"MenuSB"];
NSIndexPath *path = [self.tableView indexPathForSelectedRow];
CarObj *c = [cars objectAtIndex:[path row]];
[mvc setCurrentCar:c];
[mvc viewDidLoad]; // I am not getting previous view loaded automatically
[self dismissViewControllerAnimated:YES completion:^{}];
我在 currentCar.year 中得到的字符串无法通过使用设置标签 [yearLabel setText:currentCar.year];
最佳答案
Controller 对 [controller view] 的调用没有发生在 api 的事件链中。 因此,您在未首先加载子控件的情况下在 View 的子控件上设置的任何值都将被覆盖,让您对这个谜团感到困惑。
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
id vc = [segue destinationViewController];
MyController *controller = (MyController*)vc;
//You'll need lazy load controller child controls "now"! with this method call
[controller view];
//now you can set controls
controller.myLabel.text = @"Value will now persist";
//note objects not owned by the "view" can be set here without the hack
controller.myContextSting = @"This value will persist without the hack";
}
关于iphone - 无法使用模型 segue 在 View 上设置标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18373559/