我已经通过Cocoapods实现TSMessage到我的一个项目中。我想要继承TSMessage的类方法来设置默认的视图控制器。从TSMessage.m:未调用Objective-c子类方法 - TSMessage?
+ (UIViewController *)defaultViewController
{
NSLog(@"No view controller was set as parameter and TSMessage was not subclassed. If you want to subclass, implement defaultViewController to set the default viewController.");
return nil;
// Implement this in subclass
}
在我的课,我想继承这个方法返回我的主视图控制器。这里是我的代码在一个我的主要实现文件的顶部,ViewController.m:
@interface mySubclass : TSMessage
+(UIViewController *)defaultViewController;
@end
@implementation mySubclass
+(UIViewController *)defaultViewController{
NSLog(@"test");
ViewController *vc = [[ViewController alloc] init];
return vc;
}//end method
@end
我仍然可以登录由TSMessage说,该方法是不是子类的消息。我搜索了Google无济于事;我有一种感觉,我错过了一些超级明显的东西。我是新来的,所以请耐心等待:)
几乎可以肯定发生的事情是,任何调用defaultViewController的人都没有使用你的子类。有人需要为该方法调用[mySubclass defaultViewController]。(同样,按照惯例,类名应以首字母开头)。 – danh