当我点击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
答案 0 :(得分:0)
丹。我注意到您向类方法添加了一个按钮并绑定了事件,其中self
引用当前类,然后该按钮应绑定到类方法。
现在,您提供的button方法是一个实例方法,因此您将收到类似的错误。
+[AddressBookAccess pressButton:]: unrecognized selector sent to class 0x104d2dac8
由于您注意到事件与情节提要相关,因此建议您在实例方法中创建一个按钮并绑定事件。