0

私はto-doアプリケーションを作成しているプロジェクトに取り組んでおり、機能に各セルの追加ボタンを与え、そのボタンをクリックすると子セルを追加したいテーブルビューで作成していますクリックされたセルに階層が追加され、すべてのセルで同じになります。これを行う方法を教えてください。とても感謝しています。

前もって感謝します。コードは次のとおりです。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{


    static NSString *CellIdentifier = @"Cell";

    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
     if (cell == nil)
     {


        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
     }





    UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd];
    button.tag = indexPath.row;
    button.frame = CGRectMake(280.0, 10, 25, 30.0); // x,y,width,height

[button addTarget:self action:@selector(buttonclicked:) forControlEvents:UIControlEventTouchUpInside];
    [cell addSubview:button];

    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:cell action:nil];
    longPress.delegate = self;
    [cell addGestureRecognizer:longPress];

    int count = 0;
    if(self.editing && indexPath.row != 0)
        count = 1;
    NSLog([NSString stringWithFormat:@"%i,%i",indexPath.row,(indexPath.row-count)]);

    // Set up the cell...
    if(indexPath.row == ([_choices count]) && self.editing)
    {
        cell.textLabel.text = @"ADD";
        return cell;
    }

    NSString *choice = [self.choices objectAtIndex:indexPath.row];

    cell.textLabel.text = choice;



    return cell;
}
4

1 に答える 1

0

ボタンのアクションで、このコードを追加します

[yourTableViewObject beginUpdates];

DidSelectRowatIndexPath で、挿入するインデックスを取得します。

NSIndexPath *insertPath = [NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section];

IndexPath に行を挿入します:-

[yourTableViewObject insertRowsAtIndexPaths:[NSArray arrayWithObject:insertPath] withRowAnimation:UITableViewRowAnimationTop];

[yourTableViewObject endUpdates];
于 2013-03-18T09:48:11.897 に答える