[英]UIButton that's created programmatically crashing when method called
我有一個rootViewController並有一個以編程方式創建的UIButton。 我希望這個UIButton顯示另一個視圖控制器。 由於某些原因,它崩潰並顯示以下錯誤:
體系結構i386的未定義符號:
“ _OBJC_CLASS _ $ _ TutorialViewController”,引用自:RootViewController.o中的objc-class-ref ld:找不到體系結構i386的符號collect2:ld返回1退出狀態
這是創建Info UIButton的代碼。 這段代碼在loadView方法中:
// Create a Button to get Help
UIButton *helpButton = [UIButton buttonWithType:UIButtonTypeInfoDark ] ;
CGRect buttonRect = helpButton.frame;
// CALCulate the bottom right corner
buttonRect.origin.x = self.view.frame.size.width - buttonRect.size.width - 8;
buttonRect.origin.y = buttonRect.size.height - 8;
[helpButton setFrame:buttonRect];
[helpButton addTarget:self action:@selector(doHelp:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:helpButton];
}
這是過渡到另一個視圖控制器的動作:
- (IBAction)doHelp:(id)sender{
NSLog(@"help button pressed");
TutorialViewController *sampleView = [[[TutorialViewController alloc] init] autorelease];
[sampleView setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:sampleView animated:YES];
}
謝謝你的幫助。
阿迪格可能是正確的。
而且,從技術上講,這不是“崩潰”。 它“由於鏈接器錯誤而無法構建”。 您可以說這是一個鏈接器錯誤,因為它說“ ld返回了1個退出狀態”。 ld是鏈接器。
在后台,XCode在運行之前會編譯並鏈接您的代碼。 如果在編譯或鏈接過程中失敗,則是“構建失敗”,而不是“崩潰”。 崩潰是指在構建應用程序后突然在運行時停止。 一個常見的原因是訪問一個nil指針。
在“編譯源”列表下的“構建階段”中,檢查“目標”設置中的列表中是否包含TutorialViewController.m文件。
而不是(IBAction)doHelp:(id)sender
您必須編寫(void)doHelp
....嘗試此:)
您是#導入.h文件,而不是.m文件嗎?
問題不在於您的UIButton,問題在於TutorialViewController類未正確編譯。
非常基本,但somtime我們可能會錯過:)您是否在.h文件中聲明了相同的方法?
我認為您必須寫(void)
而不是(IBAction)
(void)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.