首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UISwitch返回NULL?

UISwitch返回NULL?
EN

Stack Overflow用户
提问于 2011-05-31 04:43:58
回答 1查看 363关注 0票数 0

由于某种原因,我有一个返回(null)的UISwitch。下面是我的代码:

AddAlbumViewController:

代码语言:javascript
复制
// .h 
IBOutlet UISwitch *photostreamSwitch;
@property (nonatomic, retain) IBOutlet UISwitch *photostreamSwitch;

// .m
@synthesize photostreamSwitch;
photostreamSwitch = [[UISwitch alloc] init];
NSLog(@"photostreamSwitch: %@", photostreamSwitch); // returns a not-null value

SecondViewController:

代码语言:javascript
复制
//.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。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-05-31 04:52:25

视图控制器已创建,但其视图(即其nib)尚未加载,因此该属性尚未连接。您可以通过访问控制器的视图成员来强制加载笔尖:

代码语言:javascript
复制
- (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];
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6180610

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档