【发布时间】:2015-04-07 03:02:36
【问题描述】:
我遇到了以下问题。
我创建了一个自定义视图控制器,其中包含一些我需要的有用方法。
这是.h中的代码
@interface MYViewController : UIViewController
- (void)method;
- (void)otherMethod;
@end
这是我的 MYViewController 类的 init 方法:
- (instancetype)init
{
self = [super init];
return self;
}
然后,当我尝试扩展该类时,我无法设置子控制器的标题。例如,在“MYOtherController.h”中
@interface MYOtherViewController : MYViewController
- (void)childControllerMethod;
@end
这是 MYOtherViewController 的初始化:
- (instancetype)init
{
self = [super init];
return self;
}
然后,如果我实例化一个 MYOtherViewController 对象并尝试设置标题,它什么也不会发生。例如:
MYOtherViewController *controller = [[MYOtherViewController] alloc] init];
controller.title = @"Hello";
如果我把它放在 MYOtherViewController 类的 viewDidLoad 中,它会记录标题为 nil:
- (void)viewDidLoad {
NSLog(@"title: %@", self.title);
[super viewDidLoad];
}
为什么不能在这个子类中设置标题?
【问题讨论】:
标签: ios objective-c uiviewcontroller