私はテーブルビューを持っています。そして、IMは、各セルに2つのボタンが追加:表が「編集」モードのときにプログラムでUIButtonを追加するとUITableViewのバグが発生する
- (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];
newBtn = [[UIButton alloc]init];
newBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[newBtn setFrame:CGRectMake(250,10,25,55)];
[newBtn addTarget:self action:@selector(addLabelText:) forControlEvents:UIControlEventTouchUpInside];
[newBtn setTitle:@"+" forState:UIControlStateNormal];
[newBtn setEnabled:YES];
newBtn.hidden = YES;
[cell addSubview:newBtn];
subBtn = [[UIButton alloc]init];
subBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[subBtn setFrame:CGRectMake(280,10,25,55)];
[subBtn addTarget:self action:@selector(subtractLabelText:) forControlEvents:UIControlEventTouchUpInside];
[subBtn setTitle:@"-" forState:UIControlStateNormal];
[subBtn setEnabled:YES];
subBtn.hidden = YES;
[cell addSubview:subBtn];
}
return cell;
}
と私は最初に隠されたボタンを持つようにしたい、そして、私は、これらのボタンを表示します。テーブルが「編集」モードを離れると、ボタンは消えます。
これを行うには、セルボタンの1つを取得できます。
- (IBAction)editButton:(id)sender
{
if (self.editing)
{
[self setEditing:NO animated:YES];
[self.myTableView setEditing:NO animated:YES];
EditButton.title = @"Edit";
subBtn.hidden = YES;
newBtn.hidden = YES;
}
else
{
[self setEditing:YES animated:YES];
[self.myTableView setEditing:YES animated:YES];
EditButton.title = @"Done";
subBtn.hidden = NO;
newBtn.hidden = NO;
}
}
しかし、問題は次のとおりです。これを行うと、最後のセルだけがボタンを取得します。彼らは私が欲しいときに正確に現れ、消えますが、最後の細胞だけです!他のセルにはボタンがありません。誰かが私を助けてくれますか?本当にありがとう!
少し説明してください。イムノブ!笑「サブコール」ってどういう意味ですか?あまりに面倒でもない場合は、私はそれを勉強して自分のプログラムで使用できるようなサンプルコードを提供してください。助けてくれてありがとう! – iProRage
また、私のボタンは最後のセルのボタンにどのように「ポイント」しますか?私はどのコードがそれをしているのかわからない!再度、感謝します! :D – iProRage
私は 'サブクラス'を意味しました。あなたが行うたびに見てください "subBtn = [[UIButton alloc] init];"あなたのポインタは明らかにオーバーライドされているので、最後には最後のセルのボタンを指しています。これをよりよく説明する方法を知らないでください。 –