UIActionSheet 取消按钮不断使我的应用程序崩溃
我对这个实在是百思不得其解。我在我的应用程序中设置了两个 UIActionSheets。它们工作得很好,直到您使用 UIActionSheets 中的取消按钮。
当我离开该页面时,UIAactionSheet 也会返回,它会使我的应用程序崩溃。
有谁也有任何想法为什么?
-(IBAction) phoneButtonClicked:(id)sender
{
// open a dialog with just an OK button
phoneActionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:self cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:[NSString stringWithFormat:@"Phone: %@",phone],nil];
phoneActionSheet.actionSheetStyle = UIActionSheetStyleDefault;
[phoneActionSheet showInView:self.view]; // show from our table view (pops up in the middle of the table)
[phoneActionSheet release];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (actionSheet == phoneActionSheet) {
if(buttonIndex == 0){
NSString *callPhone = [NSString stringWithFormat:@"tel:%@",phone];
NSLog(@"Calling: %@", callPhone);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone]];
}
}
}
I am really puzzeled by this one. I have set up two UIActionSheets in my application. They work perfectly fine until you use the cancel button in the UIActionSheets.
When i navigate away from the page the UIAactionSheet returns too it crashes my app.
Does anyone have any ideas as too why?
-(IBAction) phoneButtonClicked:(id)sender
{
// open a dialog with just an OK button
phoneActionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:self cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:[NSString stringWithFormat:@"Phone: %@",phone],nil];
phoneActionSheet.actionSheetStyle = UIActionSheetStyleDefault;
[phoneActionSheet showInView:self.view]; // show from our table view (pops up in the middle of the table)
[phoneActionSheet release];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (actionSheet == phoneActionSheet) {
if(buttonIndex == 0){
NSString *callPhone = [NSString stringWithFormat:@"tel:%@",phone];
NSLog(@"Calling: %@", callPhone);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone]];
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议不要在phoneButtonClicked 中释放phoneActionSheet。我怀疑您可能正在尝试用错误的指针做一些事情。另一个很好的帮助是使用 NSZombieEnabled。
I would suggest not releasing the phoneActionSheet in phoneButtonClicked. I suspect you might be trying to do something with a bad pointer. Another good help is to use NSZombieEnabled.