开发者

Switch Multi UITableViews in a UITableViewController

I have a UITableViewController contains two UITableViews appsTableView and gameTableView, first I set :

self.tableView = appsTableView;
    [self.view addSubview:self.tableView];

then when 开发者_如何学编程I click switch page button to do page switch:

-(void) switchPage:(id) sender{


    switch([sender selectedSegmentIndex]){
        case 0: 

            gameTableView = self.tableView;
            self.tableView = appsTableView;  // crash here

           [self.view addSubview:self.tableView];
            break;
        case 1: 

            appsTableView = self.tableView;
            [self.tableView removeAllSubviews];
            self.tableView.removeFromSuperview;

            self.tableView = gameTableView;    //crash here
            [self.view addSubview:self.tableView];

            break;   
        default: sql = nil;
    }

}

both appsTableView and gameTableView have been initialed. How can I do the switch?


How are the two table views created? I would recommend creating instance variables for them, and retain them when necessary.

self.gameTableView = ... // gameTableView is a retain property
self.appsTableView = ... // appsTableView is a retain property

Then for the switch:

self.tableView = gameTableView;

I don't think you need to remove the original table view from the super views as the self. syntax should do that for you. I'm not 100% sure about this though, I'll experiment and get back to you.

Edit: you should be safe with the direct assignment (no need to remove from super view).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜