簡體   English   中英

全選,全選並在自定義表格視圖中選擇特定的單元格

[英]Select All,Deselect All and select particular cell in custom table view

我使用表格單元格創建了一個下拉列表,其中顯示了我的數據。 我的數據將顯示在下拉菜單中。現在,我希望首先選擇所有單元格。 我也想取消選擇所有單元格和單個單元格。

(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”代碼。如何執行此操作。

您可以使用以下方法選擇和取消選擇單元格

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM