私はテーブルビューを持っています。私はもともとセルのtextLabelを使ってこれを処理していましたが、それはうまくいきませんでした。プログラムごとに各セルにUILabelを追加し、2つのボタンを追加ボタンと押しボタンを押すと基本的にカウントダウンします。 (アップまたはダウン1経つ)は、2つのボタンのための方法がある:私はボタンを押下し、複数のセルを追加したとき私のテーブルビューに奇妙なことが起こっています
- (IBAction)addLabelText:(id)sender{
cellLabel.text = [NSString stringWithFormat:@"%d",[cellLabel.text intValue] +1];
}
- (IBAction)subtractLabelText:(id)sender
{
if ([[cellLabel text] intValue] == 0){
cellLabel.text = [NSString stringWithFormat:@"%d",[cellLabel.text intValue] +0];
}
else{
cellLabel.text = [NSString stringWithFormat:@"%d",[cellLabel.text intValue] -1];
}
}
は、ボタンは、互いのラベルに干渉しました。だから私は、上記の各メソッドにこのコード行を追加しました。 :
cellLabel = (UILabel*)[sender superview];
で、問題を修正することを期待しています。しかし、実際には、私は再びtextLabelセルを信じていました。ここに、新しい行が追加されたボタンの1つを押す前と後の様子を写真で示します。
後:
細胞のUILabel年代互いに干渉するのボタンを固定して任意の助け助けてください! :あなたのコードはまだ細かい動作しても、あなたは間違ってそれをキャスト理由ですので、またtext
性質を持っているのUITableViewCellであなたのUIButtonのDおかげ
- (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(280,10,25,55)];
[newBtn addTarget:self action:@selector(subtractLabelText:) forControlEvents:UIControlEventTouchUpInside];
[newBtn setTitle:@"-" forState:UIControlStateNormal];
[newBtn setEnabled:YES];
[cell addSubview:newBtn];
subBtn = [[UIButton alloc]init];
subBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[subBtn setFrame:CGRectMake(250,10,25,55)];
[subBtn addTarget:self action:@selector(addLabelText:) forControlEvents:UIControlEventTouchUpInside];
[subBtn setTitle:@"+" forState:UIControlStateNormal];
[subBtn setEnabled:YES];
[cell addSubview:subBtn];
cellLabel = [[UILabel alloc]init];
[cellLabel setFrame:CGRectMake(85, 22, 27, 27)];
[cellLabel setText:@"1"];
[cell addSubview:cellLabel];**
}
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
cell.imageView.image = [imageArray objectAtIndex:indexPath.row];
// cell.textLabel.text = [cells objectAtIndex:indexPath.row];
**if ([cell.imageView.image isEqual:[UIImage imageNamed:@"paddle5.png"]]) {
[cellLabel setFrame:CGRectMake (195, 22, 30, 30)];
}
if ([cell.imageView.image isEqual:[UIImage imageNamed:@"paddle4.png"]]) {
[cellLabel setFrame:CGRectMake (170, 22, 30, 30)];
}
if ([cell.imageView.image isEqual:[UIImage imageNamed:@"paddle3.png"]]) {
[cellLabel setFrame:CGRectMake (140, 22, 30, 30)];
}
if ([cell.imageView.image isEqual:[UIImage imageNamed:@"paddle2.png"]]) {
[cellLabel setFrame:CGRectMake (110, 22, 30, 30)];
}**
return cell;
}
iOS5用にビルドする場合は、2つのUIButtonの代わりにUIStepperを使用することができます。 –