1

編集モードでセル内のボタンを非表示にできますか?私のセルは配列ごとに入力され、plistに保存されます。これは私のコードです

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [titleArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"the indexpath.row = %i",indexPath.row);

    UITableViewCell *cell = [[UITableViewCell alloc]init];

    button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button setFrame:CGRectMake(250.0, 25.0, 30.0, 30.0)];
    [button setTitle:@"!" forState:UIControlStateNormal];
    [button setTitle:@"X" forState:UIControlStateSelected];
    [button setTag:indexPath.row + 100];
    [button addTarget:self action:@selector(onoffBtn:) forControlEvents:UIControlEventTouchUpInside];

    // my label code

    UIImageView *bgCell = [[UIImageView alloc]initWithFrame:CGRectMake(0,0 , 320, 80)];
    bgCell.image = [UIImage imageNamed:@"BG.jpeg"];

    [cell.contentView addSubview:button];
    // other cell contentView addSubview everything

    return cell;
    [tableView reloadData];
}

これは私の編集ボタンです

- (IBAction)editBtn:(id)sender
{
    UIButton *editBtn = (UIButton *)sender;
    editBtn.selected = !editBtn.selected;

    if (editBtn.selected)
    {
        button.hidden = YES;
        [self.tableView setEditing:YES animated:YES];
    }
    else
    {
        button.hidden = NO;
        [self.tableView setEditing:NO animated:YES];
    }
}

上記のコードでは、ボタンは最後のセルにのみ非表示になります。セルが3つある場合に限ります。編集モードですべてのボタンを非表示にするにはどうすればよいですか?すべてのボタンを非表示にします。以下は私のonoffBtnです。

- (IBAction)onoffBtn:(id)sender
{
    tempIndexPath = [_tableView  indexPathForCell:(UITableViewCell*)[[sender superview] superview]];
    UITableViewCell *cell = [_tableView cellForRowAtIndexPath:tempIndexPath];
    UIButton *onoffBtn = (UIButton *)[cell.contentView viewWithTag:tempIndexPath.row+100];

    onoffBtn.selected = !onoffBtn.selected;
    if (onoffBtn.selected)
    {
        // start
    }
    else
    {
        // stop
    }
}

もっと教えてください。ありがとうございました。

4

1 に答える 1

1

テーブルのすべての UiTableViewCells に対してこのメ​​ソッドを呼び出す必要があります。

 if (editBtn.selected)
        {

for (int row = 0, rowCount = [_iTableView numberOfRowsInSection:0]; row < rowCount; ++row) {
        UITableViewCell *cell = [_iTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:0]];

      UIButton *onoffBtn = (UIButton *)[cell.contentView viewWithTag:tempIndexPath.row+100];
     onoffBtn.hidden=YES;
    }
   }
于 2012-08-11T08:32:36.027 に答える