iphone +在表格视图中未选择第10行单选按钮

时间:2011-09-20 13:21:32

标签: iphone

我有一个表视图,每行包含两个单选按钮(YES / NO类型),但是我的逻辑工作到第0行后不起作用(第9行单选按钮未选中)。请帮帮我这个

提前致谢

这是代码:

.m文件

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *CellIdentifier = [NSString stringWithFormat:@"%d-%d",indexPath.section, indexPath.row];
    QuesAnsListCustomCell *cell = (QuesAnsListCustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier] ;
    if (cell == nil) {
        [[NSBundle mainBundle] loadNibNamed:@"QuesAnsListCustomCell" owner:self options:nil];
        cell = _customCell;
        cell._delegate = self;
    }
    cell.selectionStyle= UITableViewCellSelectionStyleNone;
    DOQCategory *cat = [m_Vizuera.m_QuestionsCategoryList.m_QuestionsCategoryListArray objectAtIndex:indexPath.section];
    DOQQuestion *ques = [cat.m_CategoryArray objectAtIndex:indexPath.row];

    cell._queTxtView.text = [ques.m_Attr valueForKey:@"QNAME"];
    cell._queTxtView.font = [UIFont systemFontOfSize:14];
    cell._option1Label.text = [ques.m_Attr valueForKey:@"OPTION1_TEXT"];
    cell._option2Label.text = [ques.m_Attr valueForKey:@"OPTION2_TEXT"];
    NSString *_key = [NSString stringWithFormat:@"%d%d",(indexPath.section+1),(indexPath.row+1)];
    NSLog(@"Key  :  %@",_key);
    NSString *_result = [_userSelection valueForKey:_key];
    NSLog(@"Value : %@",_result);

    if ([_result isEqualToString:@"Y"]) {
        cell._option1Btn.imageView.image = [UIImage imageNamed:@"yes.png"];
        cell._option2Btn.imageView.image = [UIImage imageNamed:@"no.png"];
    } else {
        cell._option1Btn.imageView.image = [UIImage imageNamed:@"no.png"] ;
        cell._option2Btn.imageView.image = [UIImage imageNamed:@"yes.png"];
    }
    cell._option1Btn.tag = ((indexPath.section+1)*10)+(indexPath.row+1);
    cell._option2Btn.tag = ((indexPath.section+1)*10)+(indexPath.row+1);

    return cell;
}

-(void) respondToLeftBtnAction:(UIButton*) sender {
    if(debug)NSLog(@"In the left 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);

    if(debug)NSLog(@"section number : %d", sender.tag/10);
    if(debug)NSLog(@"Row number : %d ", sender.tag%10);
    QuesAnsListCustomCell *cell = (QuesAnsListCustomCell *) [self.theTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:section]];

    [cell._option1Btn setImage:[UIImage imageNamed:@"yes.png"] forState:UIControlStateNormal];
    [cell._option2Btn setImage:[UIImage imageNamed:@"no.png"] forState:UIControlStateNormal];

    VizueraQAppDelegate *appDelegate = (VizueraQAppDelegate *)[[UIApplication sharedApplication] delegate];

    BOOL selected = YES;
    NSString *tagIDStr = [NSString stringWithFormat:@"%d",sender.tag];
    NSLog(@"Tag number while adding to the selIndexQuestionArray : %@",tagIDStr);
    [_userSelection setValue:@"Y" forKey:tagIDStr];
    [appDelegate checkActionQuestion:tagIDStr add:selected];
}

-(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);

    if(debug)NSLog(@"section number : %d", sender.tag/10);
    if(debug)NSLog(@"Row number : %d ", sender.tag%10);
    QuesAnsListCustomCell *cell = (QuesAnsListCustomCell *) [self.theTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:section]];

    [cell._option1Btn setImage:[UIImage imageNamed:@"no.png"] forState:UIControlStateNormal];
    [cell._option2Btn setImage:[UIImage imageNamed:@"yes.png"] forState:UIControlStateNormal];

    VizueraQAppDelegate *appDelegate = (VizueraQAppDelegate *)[[UIApplication sharedApplication] delegate];
    BOOL selected = NO;
    NSString *tagIDStr = [NSString stringWithFormat:@"%d",sender.tag];
    [_userSelection setValue:@"N" forKey:tagIDStr];
    if(debug)NSLog(@"Tag number while adding to the selIndexQuestionArray : %@",tagIDStr);
    [appDelegate checkActionQuestion:tagIDStr add:selected];
}

1 个答案:

答案 0 :(得分:0)

int row =(sender.tag%10 -1);   我认为它必须在你的两个函数中使用这一行代码。   %将返回小于或等于9.并且-1将使其为8.因此0到8正在工作,即9个单元格,第10个未选择。