为什么继承必须以NSObject开头,然后在另一个类中使用继承?为什么继承需要是“子类”NSObject?
不知道为什么我有一个UIViewController的子类“FatherClass”。 所以我想创建一个继承FatherClass(ChildClass:FatherClass)。
我不能这样做,我得到一个错误日志。 我在这里搜索的所有例子都是以NSObject作为父亲开始的。
所以我的问题是这样吗?或者我错了某处。
以下是错误日志
#0 0x33d6c6f8 in CFStringGetCharacters()
CoreFoundation`CFStringGetCharacters:
0x33d6c6f8: push.w {r8, r10}
感谢
与代码
FatherClass.h
@class ChildClass;
@interface FatherClass : UIViewController <UITabBarControllerDelegate, UINavigationBarDelegate, UIPopoverControllerDelegate, MKMapViewDelegate, MKAnnotation>
{
//Some variables
}
@property (nonatomic, strong) ChildClass *sidebar_table_controller;
-(void) show_modal: (id) sender; // Thats the Method i want to call
@end
FatherClass.m
012编辑在这里#import "FatherClass.h"
#import "ChildClass.h"
@interface FatherClass()
@end
@implementation FatherClass
@synthesize sidebar_table_controller;
// All inits here... DidiLoad, DidUnload, etc..
-(void) show_modal: (id) sender // Thats the Method!!!
{
// All initiate ChildClass an then.. present modal
[self presentModalViewController:self.sidebar_table_controller animated:YES];
NSLog(@"Clicked ?...%@", sender);
}
@end
现在孩子
ChildClass.h
@interface ChildClass : FatherClass <UINavigationControllerDelegate, UITableViewDataSource, UITableViewDelegate>
@end
ChildClass.m
#import "ChildClass.h"
@interface ChildClass()
@end
@implementation ChildClass
// All inits here... DidiLoad, DidUnload, etc..
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Here i want to call Father Method
[FatherClass show_modal:indexPath];
}
@end
当我改变ChildClass:UIViewController中以ChildClass:FatherClass我的应用程序崩溃。
从UIViewController继承没有任何问题。显示代码,了解如何创建“FatherClass”和“ChildClass”。创建这些类时,是否会收到编译器的错误或警告? – 2012-04-24 16:03:39
奇怪的是,这是使用BreakPoint和没有BreakPoint时唯一的错误。 但我会编辑我的问题并输入代码给你看。 – 2012-04-24 16:12:56
如果没有与用于创建UIViewController的子类的代码相关的编译器错误或警告,则可能需要堆栈回溯。CFStringGetCharacters()中的单个x86指令确实不足以说明发生了什么。 – 2012-04-24 16:28:56