objective-c - 调用 UIActionSheet 时应用程序崩溃

标签 objective-c ios ipad

我正在为 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/

相关文章:

objective-c - 如何在 View Controller 而不是应用程序委托(delegate)中创建选项卡栏 Controller ? IOS 4.1

objective-c - 如何检测打印操作何时完成?

iphone - iOS如何计算曲线包围的像素数/面积?

iphone - 为什么从 Nib 加载的 View 被放置在状态栏下方 20 像素处?

ios - 在为iOS应用添加64位支持的同时,首选使用int值的方法

ios - MobAD 插页式退出后无法识别触摸 - Swift

ios - 如何在捕获图像时在相机屏幕中添加任何自定义图像?

json - 使用 Facebook iOS SDK 时 PhoneGap 和 SBJSON 重复冲突

iphone - 使用 Nuance SDK : Generate . wav 文件在 iPhone 中进行文本到语音转换

iphone - 通过操作将 PanGesture 应用于另一个类中的 uiview