我是新来xCode和objective-c,并尝试使用不同的类来熟悉我的语言。NSMutableArray,与UIImage和NSString对象,无法使用对象
我试图用一个NSMutableArray来显示几张图片和一个相应的textsnippet来告诉图片。我有一个segmentedControl在几个选择之间切换。使用UIImageView显示图片,并使用UITextView相应的文本。
但由于某些原因,他们将无法正确加载?图片和文字未显示。我究竟做错了什么?
@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;
}
}
感谢您的帮助那里。
实现你所说的话,但现在我只是SIGABORT得到。 – Miko 2012-02-07 10:53:08
使用ARC?在控制台中是否有任何错误描述? – Shubhank 2012-02-07 10:56:57
我第一次使用图片和文本开始,但是这是在interfacebuilder中完成的,当我按下segmentedControll时出现SIGABRT。 – Miko 2012-02-07 11:16:36