【发布时间】:2012-02-26 16:39:49
【问题描述】:
我有以下问题: 我使用 Storyboard 创建了一个 iOS 5 SDK 应用程序,其中包含一个 TabBar 和三个 ViewController。 从另一个类(Receiver.m)我想访问一个 UI 标签,例如ThirdViewController.m 是 TabBar 的 ViewController 之一。
在 ThirdViewController.h 我得到了
@interface ThirdViewController : UIViewController {
}
@property (weak, nonatomic) IBOutlet UILabel *textlabel1;
@end
在 ThirdViewController.h 中:
@implementation ThirdViewController
@synthesize textlabel1;
...
这似乎没问题,因为我可以从 ThirdViewController 实例中设置标签属性。 现在要从 Receiver.m 中获取访问权限,我使用:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];
ThirdViewController *myVC = [storyboard instantiateViewControllerWithIdentifier:@"ThirdViewController"];
myVC.textlabel1.text = @"Hello";
这不起作用。我不想创建 ThirdViewController 的新实例,而是访问现有的实例来仅更新 UILabel。我在 Project Navigator 中的 Storyboard 默认命名为 MainStoryboard.storyboard 。 我在获取 ThirdViewController 类实例时做错了吗?
错误提示:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
'Storyboard (<UIStoryboard: 0x190590>) doesn't contain a view controller with
identifier 'ThirdViewController''
谢谢!
【问题讨论】:
标签: ios storyboard viewcontroller