iOS UIActionSheet回调适用于模拟器,但不适用于手机

时间:2014-09-17 02:07:27

标签: ios objective-c callback uiactionsheet uiactionsheetdelegate

我有一个操作表,当单击其中一个选项成功时,在模拟器中运行时调用clickedButtonAtIndex,但在iPhone上测试时(Xcode 6中的5s),它无法到达回调。

标题......

@protocol SGETriggerToolBarDelegate
-(void)showCustomEditView;
@end

@interface SGETriggerToolBarController : UIViewController <UIActionSheetDelegate>

@property (nonatomic, assign) id <SGETriggerToolBarDelegate> delegate;
@property (nonatomic, strong) UIToolbar *toolbar;

在实施中......

// in xController.m
// ...
- (void)triggerButtonHandler
{
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select an event type"
                                                             delegate:self
                                                    cancelButtonTitle:nil
                                               destructiveButtonTitle:nil
                                                    otherButtonTitles:nil];
    for (SGETrigger *trigger in triggers)  {
        [actionSheet addButtonWithTitle:trigger.name];
    }

    [actionSheet addButtonWithTitle:@"Cancel"];
    actionSheet.cancelButtonIndex = triggers.count;

    [actionSheet showFromToolbar:self.toolbar];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == [actionSheet cancelButtonIndex]) {
        return;
    } else {
        selectedTrigger = triggers[buttonIndex];
        triggerButton.title = [NSString stringWithFormat:@"• %@ •", selectedTrigger.name];
        [delegate showCustomEditView];
    }
}
// ...

1 个答案:

答案 0 :(得分:0)

如果你得到&#34;提交由其超级视图剪辑的动作表。某些控件可能无法响应触摸&#34;

...更换

[actionSheet showFromToolbar:self.toolbar];

[actionSheet showInView:[UIApplication sharedApplication].keyWindow];

为我解决了这个问题。