【发布时间】:2011-08-10 08:08:44
【问题描述】:
我有一个操作表,它在横向方向的 iphone 上让我感到悲伤。一切都显示得很好,但在 Landscape 中,第一个真正的按钮与取消按钮具有相同的索引,因此逻辑不起作用。
我尝试使用 initWithTitle:delegate:cancelButtonTitle:破坏性ButtonTitle:otherButtonTitles:创建actionSheet,但那是一样的,我当前的代码如下;
UIActionSheet* actionMenu = [[UIActionSheet alloc] init];
actionMenu.delegate = self;
actionMenu.title = folderentry.Name;
actionMenu.cancelButtonIndex = 0;
[actionMenu addButtonWithTitle:NSLocalizedString(@"str.menu.cancel",nil)];
[self addActiveButtons:actionMenu forEntry:folderentry];
[actionMenu showInView:[self.navigationController view]];
[actionMenu release];
addActiveButtons 方法基本上是使用这样的代码配置要添加的按钮;
[menu addButtonWithTitle:NSLocalizedString(@"str.menu.sendbyemail",nil)];
有时可能有 6 个按钮,所以在横向模式下,actionSheet 会像这样显示;
我的代表是这样回应的;
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
NSLog(@"Cancel Button Index is : %d",actionSheet.cancelButtonIndex);
NSLog(@"Button clicked was for index : %d",buttonIndex);
NSString *command = [actionSheet buttonTitleAtIndex:buttonIndex];
DLog(@"COMMAND IS: %@ for index: %d",command,buttonIndex);
if ([command isEqualToString:NSLocalizedString(@"str.menu.sendbyemail",nil)]) {
// Do stuff here
}
if ( ... similar blocks ... ) { }
}
在显示的示例中,我发现 cancelButtonIndex 符合预期为 0,但第一个其他按钮的按钮索引也是如此!这意味着如果我点击第二个(保存到照片)按钮,我的调试输出如下所示;
取消按钮索引为:0
点击的按钮用于索引:1
命令是:通过电子邮件发送索引:1
我已经尝试了各种排列方式,现在我想知道我错过了什么。我已经进行了很好的搜索,但人们似乎遇到的其他问题是显示问题,而不是功能问题。
谁能看出我哪里出错了?
PS。我知道这不是最好的 UI 体验,但我认为大多数用户实际上大部分时间都是纵向的或使用应用程序的 iPad 版本,所以我准备接受横向的操作表默认行为,假设我可以让它真正发挥作用!
【问题讨论】:
标签: iphone ios landscape uiactionsheet