0

我刚刚将我的项目更新到 ios6 并发现我的 UIPicker 不再显示其中的数据。我真的不知道我能做些什么来确保它再次发生。有什么建议么?

添加角色TVC.h

#import <UIKit/UIKit.h>

@interface AddRoleTVC : UITableViewController <UIPickerViewDataSource, UIPickerViewDelegate> {

    IBOutlet UIPickerView *pickerView;
    NSMutableArray *arrayColors;
}
@end

AddRoleTVC.m

    #import "AddRoleTVC.h"
    #import "UIAlertView+error.h"
    #import "API.h"
    #include <CommonCrypto/CommonDigest.h>

    @implementation AddRoleTVC



    // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
    - (void)viewDidLoad {
        [super viewDidLoad];

        arrayColors = [[NSMutableArray alloc] init];
        [arrayColors addObject:@"Red"];
        [arrayColors addObject:@"Orange"];
        [arrayColors addObject:@"Yellow"];
        [arrayColors addObject:@"Green"];
        [arrayColors addObject:@"Blue"];
        [arrayColors addObject:@"Indigo"];
        [arrayColors addObject:@"Violet"];
    }
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView {

    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component {

    return [arrayColors count];
}

- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {

    return [arrayColors objectAtIndex:row];
}

- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {

    NSLog(@"Selected Color: %@. Index of selected color: %i", [arrayColors objectAtIndex:row], row);
}


    @end
4

1 回答 1

0

您使用了IBOutletTo Picker 视图,因此您在 .Xib 文件中设置了 Delegate 和数据源。它必须工作。

在此处输入图像描述

于 2012-10-29T03:47:48.493 回答