2013-05-03 30 views
0

在viewDidLoad中,我在第0行调用了tableview selectRowAtIndexPath,之后当我点击其他行时,第0行显示为空白。怎么了?的代码:当选择行时,第一个selectedrow显示为空

- (void)viewDidLoad 
{ 
    UITableView *leftTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 130, 300)]; 
    leftTableView.dataSource = self; 
    leftTableView.delegate = self; 
    leftTableView.tag = 0; 
    [leftTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"]; 
    dispatch_async(dispatch_get_main_queue(), ^{ 
     [leftTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:YES scrollPosition:UITableViewScrollPositionNone]; 
    }); 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableView *rightTableView = (UITableView *)[self viewWithTag:1]; 
    switch (tableView.tag) { 
     case 0: 
     { 
      self.right = self.left[indexPath.row][@"subchild"]; 
      dispatch_async(dispatch_get_main_queue(), ^{ 
       [rightTableView reloadData]; 
      }); 
     } 
      break; 
    } 
} 
+1

即使点击其他行,是否还想保留第一行?还有1个问题。在didSelectRowAtIndexPath中,你完成了代码(UITableView *)[self viewWithTag:1];但在viewDidLoad中,你给了tableView 0标签。我没有得到。 – LittleIDev 2013-05-03 05:43:33

+0

如果我点击其他行,我不想保留要选择的第一行。只是忽略标签,它们是无关紧要的。 – 2013-05-03 06:10:11

回答

0
dispatch_async(dispatch_get_main_queue(), ^{ 
    [leftTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:YES scrollPosition:UITableViewScrollPositionNone]; 
}); 

延迟之后执行此方法。 愿这能帮助你。

相关问题