由于某种原因,我有一个返回(null)的UISwitch。下面是我的代码:
AddAlbumViewController:
// .h
IBOutlet UISwitch *photostreamSwitch;
@property (nonatomic, retain) IBOutlet UISwitch *photostreamSwitch;
// .m
@synthesize photostreamSwitch;
photostreamSwitch = [[UISwitch alloc] init];
NSLog(@"photostreamSwitch: %@", photostreamSwitch); // returns a not-null valueSecondViewController:
//.m
- (IBAction)createAlbum:(id)sender {
AddAlbumViewController *addAlbumViewController = [[AddAlbumViewController alloc] initWithNibName:@"AddAlbum" bundle:[NSBundle mainBundle]];
NSLog(@"Test Switch: %@",addAlbumViewController.photostreamSwitch); // returns null
[addAlbumViewController release];
}我想我已经把所有东西都设置好了。如果这有帮助,那么AddAlbumViewController位于UINavigationController中,而SecondViewController包含UINavigationController。
发布于 2011-05-31 04:52:25
视图控制器已创建,但其视图(即其nib)尚未加载,因此该属性尚未连接。您可以通过访问控制器的视图成员来强制加载笔尖:
- (IBAction)createAlbum:(id)sender {
AddAlbumViewController *addAlbumViewController = [[AddAlbumViewController alloc] initWithNibName:@"AddAlbum" bundle:[NSBundle mainBundle]];
UIView* tempView = addAlbumViewController.view;
NSLog(@"Test Switch: %@",addAlbumViewController.photostreamSwitch); // no longer null
[addAlbumViewController release];
}https://stackoverflow.com/questions/6180610
复制相似问题