3

Iphone開発は初めてです。選択した(複数の)セル(チェックマーク付き)の値を他のビューのラベルとして表示したいテーブルビューコントローラーがあります。これを達成するにはどうすればよいですか?これは、テーブルビューセルをマークするチェックに使用するコードです

- (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 {
return UITableViewCellAccessoryNone;
}
4

1 に答える 1

3

チェックマークが付いたセルのインデックスを配列に追加し、そのインデックスの値をラベルに表示します

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *thisCell = [tableView cellForRowAtIndexPath:indexPath];
    if (thisCell.accessoryType == UITableViewCellAccessoryNone) {
        thisCell.accessoryType = UITableViewCellAccessoryCheckmark;
        [myIndexArray addObject:[NSString stringWithFormat:@"%d",indexPath.row]];
    }
    else
    {
        thisCell.accessoryType = UITableViewCellAccessoryNone;
        for(int i=0; i<myIndexArray.count; i++)
        {
            if([[myIndexArray objectAtIndex:i]intValue]== indexPath.row)
            {
                [myIndexArray removeObjectAtIndex:i];
                 break;
            }
        }
    }
}
于 2012-09-08T07:31:21.130 に答える