iOS UIActionSheet 回调适用于模拟器,但不适用于手机
Posted
技术标签:
【中文标题】iOS UIActionSheet 回调适用于模拟器,但不适用于手机【英文标题】:iOS UIActionSheet callback works in simulator but not on phone 【发布时间】:2014-09-17 02:07:27 【问题描述】:我有一个操作表,当在模拟器中运行时成功单击其中一个选项时调用 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];
// ...
【问题讨论】:
仅供参考 - 合并两个“取消”按钮行:actionSheet.cancelButtonIndex = [actionSheet addButtonWithTitle:@"Cancel"];
。
【参考方案1】:
如果你得到“Prepresenting action sheet by its superview. Some controls may not respond to touches”
更换...
[actionSheet showFromToolbar:self.toolbar];
与
[actionSheet showInView:[UIApplication sharedApplication].keyWindow];
为我解决了这个问题。
【讨论】:
以上是关于iOS UIActionSheet 回调适用于模拟器,但不适用于手机的主要内容,如果未能解决你的问题,请参考以下文章
UIPicker 和 UIActionsheet 不再工作 iOS7