こんにちは私は、ユーザーが選択されたときにサブビューから値を割り当てているカスタムuitableviewセルの単一のセクションがあります。どのようにuiableviewcellをクリアする
カスタムセルは2 textlabels、1のは、それはそれに割り当てられた「空」の文字列を持っているassingnedないがサブビューから選ばれた要素は、(割り当てされる場所他方はタイトルで構成されています。
私は単一のセルをスワイプして、ユーザーが値を割り当てている場合に、ユーザーがuilabelの内容を "空"にクリアできるようにしたいと考えています。
私は、私はuitableviewがユーザーが再びtableviewに触れるまで応答しなくなる問題を持っていますが、正常に動作します。
これは私の実装です。これが唯一の方法であるかどうか、またはスワイプを使用した後の表の応答性に問題があるため、これがより良い方法であるかどうかを知りたいと思います。
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
return @"Clear";
}
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
//Clears the correct uitableviewcell and releases the correct nsstring in the view
if (indexPath.section == 0) {
if (indexPath.row == 0) {
//reset uitableviewcell textlabel with default input "empty"
vehicleSearchCell = [tableView cellForRowAtIndexPath:indexPath];
UILabel *label2;
label2 = (UILabel *)[vehicleSearchCell viewWithTag:2];
label2.text = @"empty";
[tableView reloadData]; //may or may not need to call this now
}
else if (indexPath.row == 1) {
//reset uitableviewcell textlabel with default input "empty"
}
else if (indexPath.row == 2) {
//reset uitableviewcell textlabel with default input "empty"
}
else (indexPath.row == 3) {
//reset uitableviewcell textlabel with default input "empty"
}
}
}
}
将来のアップデート。 私はボタン(カスタムセルにはボタンがあります)を使用している別のカスタムセルもありますが、ユーザーはこれをスワイプすることもできますが、クリアボタンもこれに表示されますが、クリア後にボタンが使用されています(明らかに線量はありません)。別のセルを初めて押すことはできますが、遅延はありません。しかし、セクション0のセルのいずれかを使用する場合は、反応しません。
更新 タグを使用してセルをロードしているように思っています。これは問題を引き起こしている可能性がありますか? manufactureSearchObjectStringがあなたのクラスのメンバ変数である場合、私はあなたが割り当てられていることを前提とどのように私はこの問題を解決することができます。..
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"VehicleSearchCell" owner:self options:nil];
cell = vehicleSearchCell;
self.vehicleSearchCell = nil;
}
// Configure the cell...
cell.selectionStyle = UITableViewCellSelectionStyleNone;
if(indexPath.section == 0)
{
if(indexPath.row == 0)
{
UILabel *label1;
label1 = (UILabel *)[cell viewWithTag:1];
label1.text = @"Manufacture";
UILabel *label2;
label2 = (UILabel *)[cell viewWithTag:2];
label2.text = manufactureSearchObjectString;
}
else if(indexPath.row == 1)
{
[[NSBundle mainBundle] loadNibNamed:@"VehicleSearchCellDual" owner:self options:nil];
cell = vehicleSearchCellDual;
self.vehicleSearchCellDual = nil;
UILabel *label;
label = (UILabel *)[cell viewWithTag:1];
label.text = @"Model";
UILabel *label2;
label2 = (UILabel *)[cell viewWithTag:2];
label2.text = @"empty";
UILabel *label3;
label3 = (UILabel *)[cell viewWithTag:3];
label3.text = @"empty";
}
else if(indexPath.row == 2)
{
UILabel *label;
label = (UILabel *)[cell viewWithTag:1];
label.text = @"Year";
UILabel *label2;
label2 = (UILabel *)[cell viewWithTag:2];
label2.text = @"empty";
}
else if(indexPath.row == 3)
{
UILabel *label;
label = (UILabel *)[cell viewWithTag:1];
label.text = @"Key type";
UILabel *label2;
label2 = (UILabel *)[cell viewWithTag:2];
label2.text = keyTypeSearchObjectString;
}
}
else if(indexPath.section == 1)
{
if(indexPath.row == 0)
{
[[NSBundle mainBundle] loadNibNamed:@"VehicleSearchButtonCell" owner:self options:nil];
cell = searchButtonCell;
self.searchButtonCell = nil;
}
}
return cell;
}
代わりに[[manufactureSearchObjectString release]; manufactureSearchObjectString = [[NSString alloc] initWithString:@ "空"]; 'self.manufactureSearchObjectString = @" empty ";のような適切なプロパティー; – vikingosegundo
私は上記のコードを更新しましたが、それでも動作しません.. –
@ Jamie私はあなたのコードを上記の[manufactureSearchObjectString release] ; manufactureSearchObjectString = [[NSString alloc] initWithString:@ "empty"]; [self.tableView reloadData];私がスワイプした直後にテーブルはまだ応答しなくなっています。 –