Changing the behavior of a long UIActionSheet list in 4.2?

I see some behavior change in iOS 4.2 using UIActionSheet. I cannot find anything in the documents or forums of the Apple developers, so I'm not sure how to resolve them.

In my application list, I present the user with an action table from which she can select the list that she wants to load at startup. Obviously, this means that there will be a variable number of elements, and the control will do just fine with this. So far, about 7 points, it shows all the elements as buttons. As soon as he crosses this threshold, he places the elements in the scroll view of his choice. Prior to 4.2, it included the Cancel button in this scroll list. In 4.2, it now seems that it separates the Cancel control, leaving it as a button, and the rest of the elements scroll. The problem is that it displays the Cancel element in the list of button indices, so when I check the ButtonTitleAtIndex: buttonIndex button or in the clickedButtonAtIndex: file or didDismissWithButtonIndex :, the first element returns "Cancel", then the other element names 1. Click the " Cancel "and return" Cancel.

Has anyone else experienced this and suggested some kind of solution? Again, this worked great in 3.0, 3.1, 4.0 and 4.1.

Here is 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 = [actionSheet buttonTitleAtIndex:buttonIndex]; DLOG(@"chosen default list was: %@", defaultListName); } 
+4
source share
1 answer

Try adding a cancel button dynamically at the end instead of the initial setting:

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

It seems that we are working correctly in iOS 4.2.

+3
source

Source: https://habr.com/ru/post/1332680/


All Articles