UIActionSheet在iPad上再次出现后崩溃

时间:2011-07-02 16:47:28

标签: ipad crash uiactionsheet

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];
}
  }

2 个答案:

答案 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