iOS 7 用の Xcode 5 でシンプルなラベルと UIPickerView を実装しました。コードは次の Web サイトのコードを使用しました。すべてが正しいようです。なぜ機能しないのかわかりません。
http://www.youtube.com/watch?v=CIhqiuG8p1k
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController {
IBOutlet UILabel *label;
IBOutlet UIPickerView *Picker;
NSArray *PickerData;
}
@property (retain, nonatomic) IBOutlet UIPickerView *Picker;
@property (retain, nonatomic) NSArray *PickerData;
@end
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize Picker,PickerData;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSArray *array = [[NSArray alloc] initWithObjects:@"One",@"Two",@"Three",@"Four", nil];
self.PickerData = array;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent: (NSInteger)component {
return [PickerData count];
}
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return [self.PickerData objectAtIndex:row];
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent: (NSInteger)component {
int select = row;
if (select == 0) {
label.text = @"One Is Selected";
} else if (select == 1) {
label.text = @"Two Is Selected";
} else if (select == 2) {
label.text = @"Three Is Selected";
} else if (select == 3) {
label.text = @"Four Is Selected";
}
}
@end