English 中文(简体)
D. 挽救丁顿 物体索引
原标题:Saving buttonIndex into object(NSNumber)

我正试图将选定的Index行动重压成物体。 但为什么总是读到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
        }
    }
}

EDIT - 2nd

-(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];
        }
    }
}
最佳回答

NSNumber is an object that can hold basic types for storing in data structures like NSDictionary and NSArray. The %f in the NSLog is looking for a double. This code should be giving you a warning.

如果你做国家记录仪(@“%i”),就会得到正确的回答。

问题回答

请查证这部法律。

NSNumber *numberNs = [[NSNumber alloc] initWithInteger:buttonIndex];

希望有助于你们。





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签