[英]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.