选择全部,取消全选,然后在自定义表视图中选择特定单元格

时间:2014-03-11 12:31:05

标签: ios iphone objective-c drop-down-menu ios7

我已经使用表格单元格创建了一个下拉列表,我正在显示我的数据。我的数据显示在下拉列表中。现在我想要最初选择所有单元格。此外,我想取消选择所有细胞和单个细胞。

(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([tableView isEqual:expansionTableView]) {

   forState:UIControlStateNormal];

    if (indexPath.row == 0) {
        if ([indexPath isEqual:self.selectIndex]) {
            self.isOpen = NO;
            [self didSelectCellRowFirstDo:NO nextDo:NO];
            self.selectIndex = nil;

        }else
        {
            if (!self.selectIndex) {
                self.selectIndex = indexPath;
                [self didSelectCellRowFirstDo:YES nextDo:NO];


            }else
            {

                [self didSelectCellRowFirstDo:NO nextDo:YES];
            }
        }

    }else
    {
        objectForKey:@"surveyName"];


        NSMutableArray *list=[[NSMutableArray alloc]init];
        NSMutableArray *idlist =[[NSMutableArray alloc]init];
        for (int i=0; i<_arraySurveyName.count; i++) {
            NSMutableDictionary *dict=[_arraySurveyName objectAtIndex:i];
            NSString *surveyName=[dict valueForKey:@"SurveyName"];
            NSString *surveyID =[dict valueForKey:@"SurveyId"];
            [list addObject:surveyName];
            [idlist addObject:surveyID];

        }
        NSString *item = [list objectAtIndex:indexPath.row-1];
       NSNumber *item1= [idlist objectAtIndex:indexPath.row-1];
        str = item1;
        NSLog(@"%@",str);
        [_btn_surveyName setTitle:item forState:UIControlStateNormal];

        [expansionTableView setHidden:YES];

    }

}
else if ([tableView isEqual:expansionTableViewQtn]){
                NSString *selectedQuestion=[arrayOfQuestionDetail objectAtIndex:indexPath.section];
                [expansionTableViewQtn setHidden:YES];
                [_btn_showQuestn setTitle:selectedQuestion forState:UIControlStateNormal];
    }
}

这是我的“didSelect”代码。如何做到这一点。

1 个答案:

答案 0 :(得分:0)

您可以使用以下方法选择和取消选择单元格

- (void)selectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition;
- (void)deselectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated;

[tableView deselectRowAtIndexPath:indexPath animated:NO];//For deselecting
[tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];//For selecting