Я пытаюсь сохранить выбранный индекс таблицы действий в объект. Но почему он всегда читает 0?
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
NSNumber *type, *count;
if ([actionSheet.title isEqualToString:@"Select Taxi Type"]) {
if (buttonIndex !=3) {
type = [NSNumber numberWithInteger:buttonIndex];
UIActionSheet *taxiCountQuery = [[UIActionSheet alloc] initWithTitle:@"Select Taxi Count" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"1", @"2", @"3", nil];
taxiCountQuery.actionSheetStyle = UIActionSheetStyleBlackOpaque;
taxiCountQuery.tag = actionSheet.tag;
[taxiCountQuery showFromTabBar:self.tabBarController.tabBar];
[taxiCountQuery release];
}
}
else if ([actionSheet.title isEqualToString:@"Select Taxi Count"]){
if (buttonIndex !=3) {
NSLog(@"buttonIndex:%i", buttonIndex);
count = [NSNumber numberWithInteger:buttonIndex];
NSLog(@"type:%f", type); // always read 0
NSLog(@"count:%f", count); // always read 0
}
}
}
РЕДАКТИРОВАТЬ - 2-я часть
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
NSNumber *type = [[NSNumber alloc] init];
if ([actionSheet.title isEqualToString:@"Select Taxi Type"]) {
if (buttonIndex !=3) {
type = [NSNumber numberWithInteger:buttonIndex];
UIActionSheet *taxiCountQuery = [[UIActionSheet alloc] initWithTitle:@"Select Taxi Count" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"1", @"2", @"3", nil];
taxiCountQuery.actionSheetStyle = UIActionSheetStyleBlackOpaque;
taxiCountQuery.tag = actionSheet.tag;
[taxiCountQuery showFromTabBar:self.tabBarController.tabBar];
[taxiCountQuery release];
}
}
else if ([actionSheet.title isEqualToString:@"Select Taxi Count"]){
if (buttonIndex !=3) {
NSNumber *count = [[NSNumber alloc] initWithInteger:buttonIndex+1];
NSLog(@"buttonIndex:%i", buttonIndex);
count = [NSNumber numberWithInteger:buttonIndex +1];
NSLog(@"type:%i", [type intValue]); // always read 0
NSLog(@"count:%i", [count intValue]); // reads fine now
[count release];
}
}
}