Hello,
I am a noob and am finding it hard to know where exactly the damn error is.
Here are both my files, the first is the .h and the second.m
the error i am getting is:
error: synthesized property 'column5' must be named the same as a compatible ivar or must explicitly name an ivar
I have no idea what that means
.h file
.m file
the error shows up right at the bottom ( after @end )
°°
I am a noob and am finding it hard to know where exactly the damn error is.
Here are both my files, the first is the .h and the second.m
the error i am getting is:
error: synthesized property 'column5' must be named the same as a compatible ivar or must explicitly name an ivar
I have no idea what that means
.h file
Code:
#import <UIKit/UIKit.h>
@interface CustomPickerViewController : UIViewController
<UIPickerViewDataSource, UIPickerViewDelegate>
{
IBOutlet UIPickerView *picker;
IBOutlet UILabel *winLabel;
NSArray *column1;
NSArray *column2;
NSArray *column3;
NSArray *column4;
} NSArray *column5;
@property (nonatomic, retain) UIPickerView *picker;
@property (nonatomic, retain) UILabel *winLabel;
@property (nonatomic,retain ) NSArray *column1;
@property (nonatomic,retain ) NSArray *column2;
@property (nonatomic,retain ) NSArray *column3;
@property (nonatomic,retain ) NSArray *column4;
@property (nonatomic,retain ) NSArray *column5;
-(IBAction) spin;
@end
.m file
Code:
#import "CustomPickerViewController.h"
@implementation CustomPickerViewController
@synthesize picker;
@synthesize winLabel;
@synthesize column1;
@synthesize column2;
@synthesize column3;
@synthesize column4;
@synthesize column5;
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
}
return self;
}
- (IBAction)spin
{
BOOL win = NO;
int numInRow =1;
int lastVal =-1;
for(int i = 0; i<5; i++)
{
int newValue = random() % [self.column1 count];
if(newValue == lastVal)
{
numInRow ++;
}else
{numInRow = 1;}
lastVal = newValue;
[picker selectRow:newValue inComponent:i animated:YES];
[picker reloadComponent:i];
if(numInRow >=3){win=YES;}
}
if (win){winLabel.text = @"Win!";}else{winLabel.text = @"";}
}
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
UIImage *seven = [UIImage imageNamed:@"seven.png"];
UIImage *bar = [UIImage imageNamed:@"bar.png"];
UIImage *crown = [UIImage imageNamed:@"crown.png"];
UIImage *cherry = [UIImage imageNamed:@"cherry.png"];
UIImage *lemon = [UIImage imageNamed:@"lemon.png"];
UIImage *apple = [UIImage imageNamed:@"apple.png"];
for(int i=1; i <=5; i++)
{
UIImageView *sevenView = [[UIImageView alloc] initWithImage:seven];
UIImageView *barView = [[UIImageView alloc] initWithImage:bar];
UIImageView *crownView = [[UIImageView alloc] initWithImage:crown];
UIImageView *cherryView = [[UIImageView alloc] initWithImage:cherry];
UIImageView *lemonView = [[UIImageView alloc] initWithImage:lemon];
UIImageView *appleView = [[UIImageView alloc] initWithImage:apple];
NSArray *imageViewArray = [[NSArray alloc]
initWithObjects:sevenView, barView,crownView,cherryView,lemonView,appleView,nil];
NSString *fieldName = [[NSString alloc] initWithFormat:@"column %d, i"];
[self setValue:imageViewArray forKey:fieldName];
[fieldName release];
[imageViewArray release];
[sevenView release];
[barView release];
[crownView release];
[cherryView release];
[lemonView release];
[appleView release];
}
// [super viewDidLoad];
srandom(time(NULL));
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}
- (void)dealloc {
[picker release];
[winLabel release];
[column1 release];
[column2 release];
[column3 release];
[column4 release];
[column5 release];
[super dealloc];
}
#pragma mark -
#pragma mark Picker Data Source Methods
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{return 5;}
-(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:
@"COLUMN %d", component +1];
NSArray *array = [self valueForKey:arrayName];
return [array objectAtIndex:row];
}
@end
the error shows up right at the bottom ( after @end )
°°