2010-06-24 75 views
0

我正在创建我的第一个标签控制器应用程序。我有2个选项卡,其中有2个UIViews。我主要从界面生成器做了这一切,我在Xcode中做的是添加2个文件firstControllerView和SecController视图。我可以看到选项卡控制器正在运行,我运行了应用程序(我只是更改了选项卡中的2个UIViews上的背景颜色以查看效果)。连接到标签UIView内的标签

现在我想添加一个标签到第二个视图,并从代码设置它的文本编程。这是对我来说很重要的事情!我做错了什么。在我的SecondViewController.h它看起来像这样:

@interface SecondViewController : UIViewController { 
    IBOutlet UILabel *title; 
} 

@property (nonatomic,retain) UILabel *title; 

@end 

与.m看起来像这样...

#import "SecondViewController.h" 

@implementation SecondViewController 

@synthesize title; 

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 
- (void)viewDidLoad { 
    [title setText:@"Hello Nick"]; 

    [super viewDidLoad]; 
} 

- (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; 
} 

- (void)dealloc { 
    [title release]; 
    [super dealloc]; 
} 

@end 

在此之后,我回到界面生成器并拖累出口参考标签。当我运行模拟器时,它会崩溃。

缺少什么我在这里?这一定很简单。

回答

1

忘记为应用程序委托中的tabbarcontroller创建出口,然后将该出口连接到界面构建器中的制表符控制器。

+0

请在24h定时器后接受您自己的答案。 – 2011-06-18 08:16:55