Note that there are some explanatory texts on larger screens.

plurals
  1. POiPhone UIPickerView in UIViewController
    primarykey
    data
    text
    <p>I have a xib in which I have added a <code>UIViewController</code> named delta. The view under delta is controlled by the delta viewcontroller, not the file owner. On the delta view, I have a <code>UIViewPicker</code>. My issue is that I am programming in the <code>UIPickerView</code> in the <code>deltaviewcontroller</code> and I'm issuing <code>deltaviewcontroller</code> as the delegate and data source for the <code>UIPickerView</code>. Everything should work, but when I load the deltaviewcontroller's view, the application crashes. If I carry out everything the same way under the file's owner view, it works fine. I'm wondering if there is really a way to make the UIPickerView work with a <code>UIViewController</code> and no necessarily a file's owner.</p> <p>For references, the code:</p> <p>Header</p> <pre><code>@interface DeltaViewController : UIViewController &lt;UIPickerViewDelegate, UIPickerViewDataSource&gt; { NSMutableArray *arrayNo; IBOutlet UIPickerView *pickerView; } @property (nonatomic, retain) UIPickerView *pickerView; @property (nonatomic, retain) NSMutableArray *arrayNo; @end </code></pre> <p>Implementation</p> <pre><code>#import "DeltaViewController.h" @implementation DeltaViewController @synthesize pickerView; @synthesize arrayNo; - (void)viewDidLoad { NSMutableArray *dollarsArray = [[NSMutableArray alloc] init]; for (int i = 0; i &lt; 100; i++) { NSString *item = [[NSString alloc] initWithFormat:@"%i", i]; [dollarsArray addObject:item]; } self.arrayNo = dollarsArray; [dollarsArray release]; } #pragma mark - #pragma mark Picker Data Source Methods - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView { return 1; } - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component { return [arrayNo count]; } #pragma mark Picker Delegate Methods - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { return [arrayNo objectAtIndex:row]; } - (void)dealloc { [arrayNo release]; [pickerView release]; [super dealloc]; } @end </code></pre> <p>Please point out if I'm doing anything wrong. Help is much appreciated. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload