开发者

UIActionSheet long list behavior changed in 4.2?

I am seeing some changed behavior in iOS 4.2 with UIActionSheet. I can't find anything in Apple's developer docs or forums about it, so I'm not sure how to resolve it.

In my list app, I present the user with an actionsheet from which she can pick the list she wants to load on startup. Obviously that means there will be a variable number of items, and the control handles it fine. Until about 7 items, it shows all items as buttons. Once it crosses that threshold, it puts the items into a scroll view to choose from. Until 4.2, it included the Cancel button in that scrolling list. In 4.2, it now seems to be separating the Cancel control, leaving it as a button while putting the rest of the items into the scroll view. The problem is that it appears that it keeps the Cancel item in the list of button indices, so that when I inspect the buttonTitleAtIndex:buttonIndex in either clickedButtonAtIndex: or didDismissWithButtonIndex:, the first item returns "Cancel", then the other item titles are off by 1. Clicking the Cancel button also returns "Cancel".

Anyone else experienced this and have a suggestion for how to handle it? Again, this worked fine in 3.0, 3.1, 4.0, and 4.1.

Here's the relevant code I'm using:

- (IBAction)popupDefaultListActionSheet {
    UIActionSheet *popup = [[UIActionSheet alloc]
        initWithTitle:nil
        delegate:self
        cancelButtonTitle:@"Cancel"
        destructiveButtonTitle:nil
        otherButtonTitles:nil];
   for (List *l in allActiveLists) { // allActiveLists defined elsewhere
    [popup addButtonWithTitle:[l label]];
   }
   popup.actionSheetStyle = UIActionSheetStyleBlackOpaque;
   popup.tag = 23;
   [popup becomeFirstResponder];
   [popup showInView:[self.view.window.subviews objectAtIndex:0]];
   [popup release];
 }

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {

   DLOG(@"AppSettingsVC.actionSheet didDismissWithButtonIndex: %d", buttonIndex);
   NSString *defaultListName = [actionShe开发者_运维知识库et buttonTitleAtIndex:buttonIndex];
   DLOG(@"chosen default list was: %@", defaultListName);
}


Try adding the cancel button dynamically at the end instead of setting it up initially:

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"My Action Sheet"
                                                         delegate:self
                                                cancelButtonTitle:nil
                                           destructiveButtonTitle:nil
                                                otherButtonTitles:nil];

for (I32 i = 0; i < itemCount; i++) {
    [actionSheet addButtonWithTitle:itemText];
}

[actionSheet addButtonWithTitle:@"Cancel"];
[actionSheet setCancelButtonIndex:itemCount];

Seems to work correctly in iOS 4.2 for us at least.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜