0

I have an iPad master-detail where the main detail controller is a navigation controller and depending on the table row (in the master view controller) selected, I may or may not replace the view controller managed by the detail navigation controller.

This seems to work fine, except that I lose access to the new detail view controller's IBOutlets when this move is made.

Here's me switching the navigation controller's view controller:

CustomerDetailViewController *subview = [[CustomerDetailViewController alloc] initWithNibName:@"CustomerDetailViewController" bundle:nil];            
[subview setTitle:@"Testing"];
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
app.splitViewController.delegate = subview;
[app.detailNavigationController setViewControllers:[NSArray arrayWithObjects:subview, nil]];
[subview setData:[custData objectForKey:@"name"]];

custData is an NSDictionary containing my view information. Here is the setData command:

- (void)setData:(NSDictionary *)cust {

    NSLog(@"%@\n", [cust valueForKey:@"name"]);
    self.nameLabel.text = [cust valueForKey:@"name"];
    NSLog(@"%@\n", self.nameLabel.text);
}

So what happens is, subview becomes the new view controller but the label does not get changed - however, those two log commands are executed. The label is synthesized and wired up using IB and works if I push subview as a new view controller instead of replace it.

4

1 に答える 1

1

ビューはまだ初期化されていません。このメソッドでは、最初にアウトレットが接続されviewDidLoadます。ログ ステートメントを に入れてみてviewDidLoad、どちらが最初に呼び出されるかを確認してください。

viewDidLoadがメソッドの後に呼び出された場合、ラベルを適宜setData設定するローカル変数のみを設定できますCustomerDetailViewControllerviewDidLoad

于 2012-11-01T13:29:51.247 に答える