0

UITableViewカスタムtableviewセルがあります。私の 1 つはCell、カスタムクラスでデリゲート メソッドをUITextField処理しています。ユーザーがテキストを入力したら、リロードする必要があります。以下を実行しましたが、機能しませんでした。何か考えがあれば教えてください。textfieldtableviewCelltableview

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
    UITableView *parentTable = (UITableView *)self.superview;
    [parentTable reloadData];
}
4

10 に答える 10

3

データが変更されたという通知を受信するビュー コントローラーを登録し、受信したときにテーブルを更新します。次に、パーサーに送信させます。

登録は簡単です:

[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(reloadTableView:)
                                             name:@"reloadTableView"
                                           object:nil];

これらの通知を受け取るには、更新方法を次のように設定する必要があります。

- (void)reloadTableView:(NSNotification *)notif {
    [self.yourTableName reloadData];
}

そして、ViewDidUnload での観察をやめることが重要です:

[[NSNotificationCenter defaultCenter] removeObserver:self];

次に、パーサーで、完了したらこれを追加するだけです。

[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadTableView" 
                                                    object:nil];

ビュー コントローラー (およびその名前の通知を監視している他のユーザー) は、メッセージを受け取り、そのタスクを実行します。

ありがとう..

于 2013-06-27T05:58:58.190 に答える
1

CustomCell.h

@property (nonatomic, copy) void(^tapHandler)(NSUInteger tag);

CustomCell.m

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
    NSUInteger tag = 10; //Need to change the tag
    self.tapHandler(10);
}

Controller.m

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
 {
    // Whatever content was previously there. Add the below line in addition

     cell.tapHandler = ^(NSUInteger tag){
        [tableView reloadData];
    };

    return cell
 }

それが役に立てば幸い!

于 2013-06-27T06:06:45.630 に答える
0
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
UITableView *parentTable = (UITableView *)textField.superview.superview;
[parentTable reloadData];
}
于 2013-06-27T06:10:53.960 に答える
0

(UITableView *)self.superview;あなたはテーブルビューを取得しません。以下のコードを試してください:

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
      YourCell *cell = (YourCell *)[[textField superview] superview]; // you will get cell
      UITableView *table = cell.superview; // you will get table view
      [table reloadData];
}
于 2013-06-27T06:13:35.317 に答える
0

その小さな操作のためにテーブル ビュー全体を再読み込みしないでください。テキストフィールドがあるセルをリロードするだけです。また、セルの読み込み中にテーブル ビュー セルがデータ ソースからデータをフェッチするため、データ ソースを更新することを忘れないでください。

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
     [tableViewDataSource addObject:textField.text];//this will fill the data source with data of textfield
    CustomCell *cell = (CustomCell *)textField.superview.superview;
    NSIndexPath *indexPath = [parentTable indexPathForCell:cell];
    [parentTable reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
于 2013-06-27T06:25:11.677 に答える
0

まず、テキストファイルのスーパービューは UITableview ではなく、tableviewcell または tableviewcell.contentview です (コードによって異なります)。

次に、ビューコントローラーのメンバーまたはプロパティとしてテーブルビューを設定するだけです。

それから

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
    [self.tableview reloadData];
}
于 2013-06-27T05:57:52.630 に答える
0

これを試して、

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
    [self.parentTable reloadData];
}
于 2013-06-27T05:58:42.100 に答える
0

これを試して、

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
   [self.yourTableName reloadData];
   [self.yourTableName reloadInputViews];
}
于 2013-06-27T10:42:37.907 に答える
0
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    tableReload++;
    NSString *CellIdentifier = [NSString stringWithFormat:@"cell %d%d",indexPath.row,tableReload];

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];

        cell.textLabel.text = @"Hello";


    }
    // Configure the cell.
    return cell;
}
于 2013-06-27T06:49:29.333 に答える