0
我啓動我的cellForRowAtIndexPath。它出現了,但是當我嘗試從不同的類中引用它時,它會返回(null)
。如果我在viewDidLoad中啓動它,它可以工作,但它需要在UITableView中。在cellForRowAtIndexPath中啓動時無法獲取UISwitch的狀態?
AddAlbumViewController:
// .h
IBOutlet UISwitch *privateSwitch;
@property (nonatomic, retain) IBOutlet UISwitch *privateSwitch;
// .m
@synthesize privateSwitch;
privateSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(199, 8, 0, 0)];
[privateSwitch addTarget:self action:@selector(switchToggled:) forControlEvents: UIControlEventTouchUpInside];
[cell.contentView addSubview:privateSwitch];
SecondViewController:
// .m
TableViewAppDelegate *dataCeter = (TableViewAppDelegate *)[[UIApplication sharedApplication] delegate];
AddAlbumViewController *addAlbumViewController = [[AddAlbumViewController alloc] initWithNibName:@"AddAlbum" bundle:[NSBundle mainBundle]];
UIView *tempView = addAlbumViewController.view;
NSLog(@"privateSwitch: %@", addAlbumViewController.privateSwitch);
請幫助謝謝。
我宣佈privateSwitch,因爲我需要稍後閱讀它。我以後在初始化時使用它?此外,SecondView包含一個UINavigationController,並且AddAlbum是它包含的內容。當所有的內容都被加載時,動作就會發生。 – iosfreak 2011-05-31 02:57:21
但是您沒有在您發佈的代碼中使用該屬性。也許發佈更多的代碼?在另一個問題上,僅僅因爲視圖被加載並不意味着該表已經填充了單元格。這是兩回事。在tableView:cellForRow中放置一個日誌或斷點...以便您可以看到它何時被調用。此外,也許發佈更多的代碼,以便人們可以看到你想要做的事情的結構。 – 2011-05-31 03:01:53
當按鈕被按下時,tableView被填充。我想不出任何更多的代碼發佈。這是很多東西... – iosfreak 2011-05-31 03:07:29