0
我有一個UISwitch,由於某種原因返回(null)
。下面是我的代碼:UISwitch返回NULL?
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 value
SecondViewController:
//.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。
這樣做了!現在,如果我將它添加到我的viewDidLoad中,它會正確檢測。 (ISON)。但如果我把它放在我的cellForRowAtIndexPath中,它不會。這裏是我在我的cellForRowAtIndexPath中的代碼:'photostreamSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(199,8,0,0)]; [cell.contentView addSubview:photostreamSwitch]; [photostreamSwitch setOn:YES animated:NO];'謝謝。 – iosfreak 2011-05-30 21:04:05
我不確定你想要完成什麼。也許你可以發佈更多的代碼。 – Hollance 2011-05-31 12:18:13