我正在为 iPad 编写应用程序。在此应用程序中,我必须在所有屏幕的导航栏上使用共享按钮。我在我的 Home 类上应用了 Share 按钮。我编写了以下代码来应用导航栏上的按钮:
CGRect frame5 = CGRectMake(835.0, 0.0, 40.0, 40.0);
UIImage *buttonImage5 = [UIImage imageNamed:@"ShareIcon.png"];
UIButton *ShareButton = [UIButton buttonWithType:UIButtonTypeCustom];
ShareButton.frame = frame5;
[ShareButton setBackgroundImage:buttonImage5 forState:UIControlStateNormal];
ShareButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
ShareButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[ShareButton addTarget:self action:@selector(actionSheet) forControlEvents:UIControlEventTouchUpInside];
[ShareButton setBackgroundColor:[UIColor clearColor]];
[self.navigationController.navigationBar addSubview:ShareButton];
共享按钮用于通过电子邮件发送或打印屏幕。为此,我使用了 UIActionSheet。我编写了以下方法来应用 UIActionSheet:
-(void)actionSheet:(id)sender
{
UIActionSheet *popup = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Email", @"Print", nil];
[popup showFromRect:CGRectMake(720.0, 3.0, 40.0, 40.0) inView:[self view] animated:TRUE];
[popup showFromBarButtonItem:(UIBarButtonItem *)sender animated:TRUE];
[popup release];
}
此方法应用于分享按钮。当我构建并运行我的应用程序时,没有错误或警告,即构建成功。但是,当我单击共享按钮时,应用程序崩溃并在调试器控制台窗口中显示以下内容:
[Session started at 2011-10-21 21:26:58 +0530.]
2011-10-21 21:27:03.895 NewBostonEndoscopy[1351:207] -[Home actsht]: unrecognized selector sent to instance 0x6227010
2011-10-21 21:27:03.898 NewBostonEndoscopy[1351:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Home actsht]: unrecognized selector sent to instance 0x6227010'
我不明白为什么会这样。任何猜测? 任何帮助将不胜感激。 感谢致敬 普拉特克
最佳答案
你显示了两次弹出窗口,我不确定这是否是你崩溃的原因,但请尝试删除该行
[popup showFromRect:CGRectMake(720.0, 3.0, 40.0, 40.0) inView:[self view] animated:TRUE];
关于objective-c - 调用 UIActionSheet 时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7852540/