开发者

Push view controller logic error

Im wondering if someone can please tell me what am I missing. I got a tableview with two sections, but when I tap onto anything on section 2, content from section 1 cells is loaded. Thanks in advance.

here is my didselectrowatindexpath:

    UIViewController *targetViewController = [[views objectAtIndex:indexPath.row]开发者_JAVA百科     objectForKey:@"controller"];
   [[self navigationController] pushViewController:targetViewController animated:YES];

if (indexPath.section == 0)
      [partA  objectAtIndex:indexPath.row];
    else 
      [partB objectAtIndex:indexPath.row];

      [targetViewController release];
}


In your tableView:didSelectRowAtIndexPath: method, you may not be accounting for the section; i.e. you're pulling a UIViewController from the views array using indexPath.row, when you should probably also be using indexPath.section as a qualifier. It's hard to give a better answer without seeing more of your view controller.


You may consider to use following code instead of your if statement.

UITableViewCell * cell = [self.tableView cellForRowAtIndexPath:indexPath];

Also remove the release because you did not retain or allocate it.

But honest: I do not understand what you want to do. What do you mean by "loaded"? Loaded where?


You haven't provided it but my guess is that you should override didSelectRowAtIndexPath method and check the owner of the selecting cell:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;

{

if ( tableView == _tableView1){

     //Do something
}

else if ( tableView == _tableView2){

     //Do something different
}

else return;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜