私のテーブル(UITableView
)UITextField
isteadがUILabel
のセルを「addSubview」でセルに追加しました。私は自分の細胞を直接編集可能にしたいので、これが必要です。セルスタイルの私はUITableViewCellStyleDefault
を使用します。 - すべてうまく動作します:いつでもセルを追加したり編集したりできます。テーブルのセルを削除する際の問題
ただし、削除すると問題が発生します。セルを「削除」してテーブルをreloadData
にすると、セルには古いコンテンツと新しいコンテンツが表示されます。その下のすべてのセルについても同じです。私は、私のアプリケーションを閉じて、もう一度起動すると、テーブルが正しく表示されます。ここで
私はセル
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = [indexPath row];
NSUInteger count = [datas count];
if (row <= count) {
NSString* data = [datas objectAtIndex: [indexPath row]];
[self deleteDatas:data];
}
[self.locationTable reloadData];
}新しい負荷によって「prooved」としてdeleteDatas
に私は、正常に動作するファイルから該当する件のデータを削除
に削除するために使用するコードアプリ。ここで
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
longPressGesture.minimumPressDuration = 2.0;
[cell addGestureRecognizer:longPressGesture];
}
// Configure the cell.
// table cell with uitextfield instead of lable.
UITextField* textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 10, 185, 30)];
textField.enabled = NO;
[cell.contentView addSubview:textField];
NSUInteger count = [datas count];
NSUInteger row = [indexPath row];
// last cell is empty to edit it
if (row+1 < count) {
textField.text = [datas objectAtIndex:[indexPath row]];
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
}
return cell;
}
任意のアイデア? - ありがとう
私のセルが2倍のコンテンツを表示する理由は何ですか(元のセルの1回と1回のセルの内容?) - 私は思っています。セルを再ロードすると間違っています。 - テキストフィールドが問題を起こす可能性はありますか? - どうすればわかるの?以上のように方法:
はあなたが呼ばれるあなたの方法で記述したコード投稿することができます - (無効)にtableView:(のUITableView *)のtableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath – Tendulkar
をしても、あなたのIBOutlet接続を確認し – Tendulkar
ここにあなたのcellFroRowAtIndexPathを貼り付けます。 –