爲什麼繼承必須以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