0
我正在嘗試將操作表的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
}
}
}
編輯 - 第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];
}
}
}
不知何故,只是改變NSLog語句崩潰。 –
您需要實際將類型初始化爲某種東西。你不是當它在第二塊如果塊。 – Randall
我編輯了我的問題,包括我編輯的內容,但仍然可以使用「類型」工作。 –