私はObjective-Cが初めてで、iPhoneアプリをプログラムしようとしています。
これは私のコードです:
ヘッドファイル:
#import <UIKit/UIKit.h>
@interface TutorialViewController : UIViewController{
UILabel *labelText;
UIImageView *imageView;
}
@property(nonatomic,retain) IBOutlet UILabel *labelText;
@property(nonatomic,retain) IBOutlet UIImageView *imageView;
-(IBAction) click:(id) sender;
@end
これが実装です:
#import "TutorialViewController.h"
@implementation TutorialViewController
@synthesize labelText;
@synthesize imageView;
-(void) click:(id)sender {
imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"1.png"]];
NSString *titleOfButton = [sender titleForState:UIControlStateNormal];
NSString *newText = [[NSString alloc]initWithFormat:@"%@",titleOfButton];
// Change Image When Clicking Color Button
if([titleOfButton isEqualToString:@"Blue"]){
NSLog(@"Blue");
UIImage *image = [UIImage imageNamed:@"1.png"];
imageView.image = image;
[image release];
}else{
UIImage *image = [UIImage imageNamed:@"2.png"];
imageView.image = image;
[image release];
NSLog(@"Else");
}
labelText.text = newText;
[newText release];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#pragma mark - View lifecycle
- (void)viewDidUnload
{
[super viewDidUnload];
self.labelText = nil;
}
-(void) dealloc{
[labelText release];
[imageView release];
[super dealloc];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
アプリを起動すると、例外がスローされます:
'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "TutorialViewController" nib but the view outlet was not set.'
誰でも私のコードで私を助けることができますか?
さらに、私のコードに書かれている悪い動作について教えてください。
大変感謝します !