iphone - 无法使用模型 segue 在 View 上设置标签

标签 iphone ios ios6 storyboard segue

http://i.stack.imgur.com/TaNjH.png

problem StoryBoard

我想使用模型转场。通过单击“年”按钮,它应该转到“年 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/

相关文章:

ios - tableView 中不显示评论

iphone - CGFloats, float 设置为零

iphone - 将 pfx 文件导入 iOS 应用程序

ios - 使用UIBezierPath绘制同心圆

ios - 清除 iOS 8.4 上 WKWebView 的 Cookie

ios - 如果不使用 CoreAnimation 如何避免 "CoreAnimation warning deleted thread with uncommitted CATransaction"

iphone - Objective-C - 使用 ARC 分配/初始化对象

ios - 删除行: error 'Invalid update: invalid number of rows in section 0'

ios - 具有 RGB 的 UIColors 在屏幕上显示为基本颜色

ios - 应用程序在模拟器中交替崩溃