2011-09-08 58 views
0

我有一个表视图,在每一行中有两个单选按钮在那里,用于选择单选按钮需要计算节号和行号,并在当前的逻辑上到第9行它的工作正常,但第9行后它没有改变单选按钮图像。iphone表视图问题与index.section和index.row

这里是我的一块逻辑实现代码。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
cell._option1Btn.tag = ((indexPath.section+1)*10)+(indexPath.row+1); 
cell._option2Btn.tag = ((indexPath.section+1)*10)+(indexPath.row+1); 

    return cell; 
} 


-(void) respondToRightBtnAction:(UIButton*) sender { 
    if(debug)NSLog(@"In the Right button clicked method"); 
    if(debug)NSLog(@"left button in %d row is YES", sender.tag); 

    int section = (sender.tag/10 -1); 
    int row = (sender.tag%10 -1); 

}

+0

你在每个部分有多少行? – taskinoor

回答

0

我觉得问题可能出在这:

您将有相同的标签{部分= 0,行= 10}(标签== 21){section = 1,row = 0}(tag == 21)。尝试改变生成标签的方法。

例如,

cell._option1Btn.tag = ((indexPath.section+1)*1000)+(indexPath.row+1); 
cell._option2Btn.tag = ((indexPath.section+1)*1000)+(indexPath.row+1); 

系数()要小一些,然后在部分

2

它不会因为你是你设定的标签的方式工作的最大行数。这是一个例子。

indexPath.section = 1,indexPath.row = 1 标签= 22

indexPath.section = 0,indexPath.row = 11 标签= 22

一种更好的方式来做到这一点是获取单元格本身,您可以从发件人变量中获取单元格。

-(void) respondToRightBtnAction:(UIButton*) sender { 
    UITableViewCell *cell = sender.superview.superview //actual code will depend on the hierarchy. This assumes that the button is in the contentview of the cell 

    NSIndexPath *path = [myTableView indexPathForCell:cell]; 

    //now you can do whatever you need to do with the indexpath. 

}