Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-23-2011, 07:02 AM   #1 (permalink)
J-E
Registered Member
 
Join Date: Feb 2011
Posts: 6
J-E is on a distinguished road
Question Trouble to read plist into UIPicker

Hi !

I'm trying to get a random line from a plist, and present it to a picker when pressing a "spin-button".
What am I missing ? When running the app, it crash with the following error;"
[NSCFString superview]: unrecognized selector sent to instance".

The code:
-------------
The .h -file
-------------
Code:
 #import <UIKit/UIKit.h>


	
@interface jhaGameViewController : UIViewController
<UIPickerViewDataSource, UIPickerViewDelegate> {

	
	UIPickerView *picker;
        NSArray *column1;
	UIButton *spin;
	NSMutableArray *ViewArray;
}
@property(nonatomic, retain) IBOutlet UIPickerView *picker;
@property(nonatomic, retain) NSArray *column1;
@property(nonatomic, retain) NSMutableArray *ViewArray;

- (IBAction)spin;
@end
--------------
The .m -file:
--------------
Code:
#import "jhaGameViewController.h"
@implementation jhaGameViewController
@synthesize picker;
@synthesize column1;
@synthesize ViewArray;

- (IBAction)spin {
	
    int lastVal = -1;
    for (int i = 0; i < 1; i++) {
        int newValue = random() % [self.column1 count];
		
        if (newValue == lastVal)
			
			lastVal = newValue;
	
	[picker selectRow:newValue inComponent:i animated:YES];
        [picker reloadComponent:i];
    }
}


 - (void)viewDidLoad {
	
	 for (int i = 1; i <= 5; i++) {
		 NSString *qpath = [[NSBundle mainBundle] pathForResource:@"jhaList" ofType:@"plist"];
		 ViewArray = [[NSMutableArray alloc] initWithContentsOfFile:qpath];
		 
		
		NSString *fieldName =
		[[NSString alloc] initWithFormat:@"column1", i];
		[self setValue:ViewArray forKey:fieldName];
		[fieldName release];
		[ViewArray release];
	
	 }
	
	srandom(time(NULL));
}

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
	self.picker = nil;
        self.column1 = nil;
	self.ViewArray = nil;
}

- (void)dealloc {
    [picker release];
    [column1 release];
    [ViewArray release];
    [super dealloc];
}

#pragma mark -
#pragma mark Picker Data Source Methods
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component {
    return [self.column1 count];
}

#pragma mark Picker Delegate Methods
- (UIView *)pickerView:(UIPickerView *)pickerView
			viewForRow:(NSInteger)row
          forComponent:(NSInteger)component reusingView:(UIView *)view {
    NSString *arrayName = [[NSString alloc] initWithFormat:@"column1",
						   component+1];
    NSArray *array = [self valueForKey:arrayName];
    [arrayName release];
    return [array objectAtIndex:row];
}

@end
I'm a newbie, so I'll apriciate all help I can get !

//J-E
J-E is offline   Reply With Quote
Reply

Bookmarks

Tags
picker, plist, random, superview, uipicker

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 361
11 members and 350 guests
condor304, dansparrow, Domele, dreamdash3, ilmman, LezB44, michelle, Sami Gh, shagor012, thephotographer, tinamm64
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,119
Posts: 402,896
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:34 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0