iPhone – UIActionsheet in the horizontal direction has incorrect Buttonindicies

I have an action sheet that makes me feel sad about the horizontal iPhone. Everything is displayed very well, but in Landscape, the first real button has the same effect as the cancel button Index, so the logic does not work.

I tried to create an actionSheet using initWithTitle: delegate: cancelButtonTitle: destructiveButtonTitle: otherButtonTitles: but it is the same, my current code is as follows;

< p>

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

The addActiveButtons method basically uses such code to configure the buttons to be added;< /p>

[menu addButtonWithTitle:NSLocalizedString(@"str.menu.sendbyemail",nil)];

Sometimes there may be 6 buttons, so in landscape mode Next, the actionSheet will be displayed like this;

My representative responded like this;

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger )buttonIndex {< br />
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 ...) {}

}

In the example shown, I found that the cancelButtonIndex is 0 as expected, but the first The same goes for the button index of the other buttons! This means that if I click the second (Save to Photo) button, my debug output looks like this;

The cancel button index is: 0

Click the button for Index: 1

The command is: Send by email Index: 1

I tried various arrangements, and I am tearing my hair now, wondering what I missed . I have a good search, but the other issues people seem to have are display issues, not functionality issues.

Who can see where I am going wrong?

PS. I know this is not the best UI experience, but I think most users will actually be in portrait state or use the iPad version of the app most of the time, so I am ready to accept dynamic forms The default behavior, assuming I can make it actually work!

Okay, fix it by counting the number of buttons I added and then adding the cancel button as the last option It, so my code looks like this;

int added = [self addActiveButtons:actionMenu forEntry:folderentry];

[ actionMenu addButtonWithTitle:NSLocalizedString(@"str.menu.cancel",nil)];
actionMenu.cancelButtonIndex = added;

I hope to help others struggle with the same problem!

I have an action sheet that makes me feel sad about the horizontal iphone. Everything is displayed very well, but in Landscape, the first real button is with cancel The buttons have the same index, so the logic does not work.

I tried to create an actionSheet using initWithTitle: delegate: cancelButtonTitle: destructiveButtonTitle: otherButtonTitles: but it is the same, my current code is as follows;< /p>

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

The addActiveButtons method basically uses this code to configure to add Button;

[menu addButtonWithTitle:NSLocalizedString(@"str.menu.sendbyemail",nil)];

Sometimes there may be 6 buttons, So in landscape mode, the actionSheet will be displayed like this;

My representative responded like this;

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

NSLog(@"Ca ncel 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 ...) {}

}

In the example shown, I find that cancelButtonIndex is 0 as expected, but so is the button index of the first other button! This means that if I click the second (Save to Photo) button, my debug output looks like this;

The cancel button index is: 0

Click the button for Index: 1

The command is: Send by email Index: 1

I tried various arrangements, and I am tearing my hair now, wondering what I missed . I have a good search, but the other issues people seem to have are display issues, not functionality issues.

Who can see where I am going wrong?

PS. I know this is not the best UI experience, but I think most users will actually be in portrait state or use the iPad version of the app most of the time, so I am ready to accept dynamic forms The default behavior, assuming I can make it actually work!

Ok, fix it by counting the number of buttons I added and then adding the cancel button as the last option, so my code looks like this; < p>

int added = [self addActiveButtons:actionMenu forEntry:folderentry];

[actionMenu addButtonWithTitle:NSLocalizedString(@"str.menu.cancel ",nil)];
actionMenu.cancelButtonIndex = added;

I hope to help others struggle with the same problem!

Leave a Comment

Your email address will not be published.