Friday, December 27, 2013

UIPickerView use on a number of issues

I was under iphone3 Development Essentials write the code example above.
. H file code is as follows:
 
@ Interface YellowViewController: UIViewController {

UIPickerView * pickView;
NSArray * pickData;
UIButton * button;
}

@ Property (nonatomic, retain) UIPickerView * pickView;
@ Property (nonatomic, retain) NSArray * pickData;
@ Property (nonatomic, retain) UIButton * button;

@ End


. M in viewDidLoad method code is as follows:
 
- (Void) viewDidLoad {
self.view.backgroundColor = [UIColor blackColor];
pickView = [[UIPickerView alloc] init];
pickView.frame = CGRectMake (0, 0, self.view.frame.size.width, 200);
NSArray * array = [[NSArray alloc] initWithObjects: @ "abc", nil];
self.pickData = array;
pickView.dataSource = self;
pickView.delegate = self;
[Array release];
[Self.view addSubview: pickView];
[Super viewDidLoad];
}

I have commissioned two ways to achieve the look above the red line of code, I had written pickData = array; program will abort without reason, adding a self pointer after normal. But the default is self pointer ah, why is there such a problem? Then I finally read the book to find examples, plus a self pointer just fine. Can anyone tell me why ah. . . .
Reply:
Because pickData you define a property, there is a default set method, only after the addition of self will call the default set method
Reply:
In the. M file, realize the property getter, setter. See there is no plus
@ Synthesize pickData

No comments:

Post a Comment