actionsheet의 selectedIndex를 객체에 저장하려고합니다. 하지만 항상 0을 읽는 이유는 무엇입니까?buttonIndex를 객체 (NSNumber)에 저장
-(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
}
}
}
편집 - 두번째 부분은
-(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];
}
}
}
어떻게 든 NSLog 문을 변경하면 충돌이 발생합니다. –
실제로 형식을 초기화해야합니다. 두 번째 블록에있을 때가 아닙니다. – Randall
편집 한 내용을 포함하도록 질문을 편집했지만 '형식'을 사용할 수는 있습니다. –