UIActionSheet第二次出现后崩溃了。
.H文件
..UIActionSheetDelegate>{
UIActionSheet *popupQuery;
}
@property (nonatomic, retain) UIActionSheet *popupQuery;
.M文件
-(IBAction)showActionSheet:(id)sender {
if (popupQuery.visible) {
NSLog(@"popupQuery isVisible");
[popupQuery dismissWithClickedButtonIndex:-1 animated:YES];
return;
}else{
popupQuery = [[UIActionSheet alloc] initWithTitle:@"Title" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Readibility" otherButtonTitles:@"Email URL", @"Print", nil];
popupQuery.actionSheetStyle = UIActionSheetStyleBlackOpaque;
//[popupQuery showInView:self.view];
[popupQuery showFromBarButtonItem:actionButton animated:YES];
[popupQuery release];
}
}
答案 0 :(得分:2)
从popupQuery
显示actionButton
后释放popupQuery
时,您放弃对该对象的所有权。如果对象被释放,那么popupQuery.visible
将指向一个解除分配的对象,当你执行self.popupQuery = [[[UIActionSheet alloc] initWithTitle:@"Title" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Readibility" otherButtonTitles:@"Email URL", @"Print", nil] autorelease];
时可能会让你崩溃。由于您将其作为财产,您可以这样做 -
release
最后删除popupQuery.visible
语句。现在,当您self.poupQuery.visible
或{{1}}时,该对象将有效。在这种情况下,您将拥有所有权,并且您可以安全地访问该对象。
答案 1 :(得分:1)
来自UIActionSheet
的{{3}}:
- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated
<强>参数强>
buttonIndex
单击的按钮的索引。按钮索引从0开始。
因此,问题可能是您的-1
。