I’m new to xCode and objective-c, and trying to use different classes to familiarize myself with the language.
I was trying to use an NSMutableArray to show several pictures and a corresponding textsnippet to tell about the picture. I have a segmentedControl to switch between several choices. Using an UIImageView to show a picture, and a UITextView the corresponding text.
But for some reason they will not load properly? The picture and the text isn’t shown. What am I doing wrong?
@interface TestingViewController : UIViewController{
UIImageView *pic;
UITextView *description;
UISegmentedControl *choice;
NSMutableArray *infoDescription;
}
@property (nonatomic, retain) IBOutlet UIImageView *pic;
@property (nonatomic, retain) IBOutlet UITextView *description;
@property (nonatomic, retain) NSMutableArray *infoDescription;
@property (nonatomic, retain) IBOutlet UISegmentedControl *choice;
- (IBAction) segmentedControllIndexChanged;
@end
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
infoDescription = [[NSMutableArray alloc] init];
}
UIImage *miko = [UIImage imageNamed:@"miko.jpg"];
NSString *mikoString = @"Info about Miko";
UIImage *alex = [UIImage imageNamed:@"alex.jpg"];
NSString *alexString = @"Info about Alex";
[infoDescription addObject:miko];
[infoDescription addObject:mikoString];
[infoDescription addObject:alex];
[infoDescription addObject:alexString];
- (IBAction)segmentedControllIndexChanged{
switch (choice.selectedSegmentIndex) {
case 0:
[pic setImage: miko];
[pic setImage: [infoDescription objectAtIndex:0]];
[description setText: [[infoDescription objectAtIndex:1] stringValue]];
break;
case 1:
[pic setImage: [infoDescription objectAtIndex:2]];
[description setText: [[infoDescription objectAtIndex:3] stringValue]];
break;
default:
break;
}
}
Thanks for any help out there.
NSMutableArray should not be an IBOutlet ..
Change this
to
and make sure you synthesize it..
and also the program isn’t working since your array is not initialized and is not adding objects to it.
put this in ViewDidLoad