开发者

problem with uitableview when return

开发者 https://www.devze.com 2023-03-13 12:22 出处:网络
i have viewcontroller with table view that开发者_如何学JAVA when i click on a cell i go in the navigation to another view controller with another tableview.

i have viewcontroller with table view that开发者_如何学JAVA when i click on a cell i go in the navigation to another view controller with another tableview.

i try to use the viewDidAppear and viewWillAppear in the first viewcontroller, that when i back to this viewcontroller from the second viewcontroller i will enter one of this method.

the problem is that he didn't enter this method when i return to this viewcontroller.

this is how i enter the second view controller:

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
        ProfileViewController2 *tmp = [[ProfileViewController2 alloc]initWithType:indexPath.row string:[self.array2 objectAtIndex:indexPath.row]];
        [[self navigationController] pushViewController:tmp animated:YES];
        [tmp release];
        [self.mytableview deselectRowAtIndexPath:indexPath animated:YES];
    }


viewWillAppear and viewDidAppear are notoriously shaky on iOS.

If you are working with UITableViews we always put the code we need to run before the table gets loaded into the

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

function. It's a slight hack but works very well as this is the first function out of the UITableViewDataSource protocol called.

Alternatively, you can call

    [tmp viewDidAppear];

After pushing the view controller and before releasing tmp to force the function being called.

0

精彩评论

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