[英]App crash when UIBarButtonItem is pressed
當我點擊 UIBarButtonItem 時,我的應用程序崩潰。 我嘗試了許多不同的方法來編寫將被調用的函數,但到目前為止找不到解決方案。 我的代碼如下。 感謝您的幫助!
#import <Foundation/Foundation.h>
#include<pthread.h>
#import <Contacts/Contacts.h>
#import <ContactsUI/ContactsUI.h>
#import <ContactsUI/CNContactViewController.h>
#import <UIKit/UIKit.h>
@interface AddressBookAccess:UIViewController
@end
@implementation AddressBookAccess:UIViewController
+(BOOL)AddNewContact
{
// Removing code here
newNavigationController.navigationBar.topItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"Back to AReach" style:UIBarButtonItemStylePlain target:self action:@selector(pressButton:)];
[viewController presentViewController:newNavigationController animated:YES completion:nil];
return YES;
}
-(IBAction)pressButton:(UIBarButtonItem*)btn
{
NSLog(@"button tapped %@", btn.title);
}
@end
擔。 我注意到你在類方法中添加了一個按鈕並綁定了事件,其中self
指的是當前類,那么按鈕應該綁定到一個類方法。
現在你提供的按鈕方法是一個實例方法,所以你會得到這樣的錯誤。 +[AddressBookAccess pressButton:]: unrecognized selector sent to class 0x104d2dac8
由於您注意到您的事件與故事板相關聯,我建議您在實例方法中創建一個按鈕並綁定事件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.