-1

私はUITableviewを持っており、そのTableViewにはjsonデータが入力されています。タッチされたテーブルセルをチェックマークでチェックする、複数選択されたテーブルビューコードを実装しました。

私の質問は、どのテーブルビュー セルを選択したかをどのように確認し、選択したテーブル ビュー セルにアクションをどのように配置するかです。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.json2.count;
}

-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CellIdentifier";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] ;
}

cell.textLabel.text = self.json2[indexPath.row][@"SurveyName"];

//cell.detailTextLabel.text = self.json1[indexPath.row][@"AssetDesc"];

// Sets the accessory for the cell
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

return cell;

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

UITableViewCell *thisCell = [tableView cellForRowAtIndexPath:indexPath];


if (thisCell.accessoryType == UITableViewCellAccessoryNone) {
    thisCell.accessoryType = UITableViewCellAccessoryCheckmark;

}else{
    thisCell.accessoryType = UITableViewCellAccessoryNone;

}
}

- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath {

//add your own code to set the cell accesory type.
return UITableViewCellAccessoryNone;
}

したがって、通常、テーブルビューセルからセグエを作成する場合、次のようにします。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Perform segue
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[self performSegueWithIdentifier: @"showSurveyForm" sender:self];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"showSurveyForm"]) {
    // NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
    CameraViewController *destViewController = segue.destinationViewController;

    // Hide bottom tab bar in the detail view
    destViewController.hidesBottomBarWhenPushed = YES;
    destViewController.surveyQuestionId = self.surveyQuestionIDParsed;
    destViewController.jsonTitleforSurvey = self.json2;
    destViewController.surveyTitleAssetId = self.assetSurvey;

    NSLog(@"Survey ID for Survey: %@", self.surveyQuestionIDParsed);
    NSLog(@"Survey name titile: %@", self.json2 );
    NSLog(@"Asset ID for Title: %@", self.assetSurvey);

}

else if ([segue.identifier isEqualToString:@"showCameraRoll"]) {
    // NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];

    // Hide bottom tab bar in the detail view
}

else if ([segue.identifier isEqualToString:@"showJsonData"]) {
    // NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];

}

else if ([segue.identifier isEqualToString:@"testPickerDemo"]) {
    // NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];

}
}

UItableview で複数選択したセルを選択した後、セグエを作成したいと思います。

たとえば、選択を行い、2 つの行がチェックされます。どのテーブルビュー セルが選択されたかを nslog でキャプチャまたは確認したいので、選択した行に基づいて別の json 呼び出しとセグエを実行できます。

json を呼び出して解析し、セグエを作成する方法を知っています。

ここに画像の説明を入力

4

1 に答える 1

3

-didSelectRowAtIndexPath次のように変更できます。

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    {
        UITableViewCell *thisCell = [tableView cellForRowAtIndexPath:indexPath];
        NSString *selStr = [yourSourceArray objectAtIndex:indexPath.row];
--->        NSMutableArray *selArray = [[NSMutableArray alloc] init];    //Write this line in viewDidLoad method.
        if (thisCell.accessoryType == UITableViewCellAccessoryNone) 
        {
            thisCell.accessoryType = UITableViewCellAccessoryCheckmark;
            [selArray addObject:selStr];
        }
        else
        {
            thisCell.accessoryType = UITableViewCellAccessoryNone;
            [selArray removeObject:selStr];
        }
        NSLog(@"selArray :: %@",selArray);
    }

アップデート :

Selected Rows の textLabel のテキストの配列が得られます。-yourButtonPressed次に、メソッドで使用できます

- (IBAction)yourButtonPressed:(id)sender;
{
    NSLog(@"selArray :: %@",selArray);
}

幸運を !!!

于 2013-05-27T09:40:41.037 に答える