35

配列を使用して入力される詳細開示ボタンを作成しています....しかし、accessoryButtonTappedForRowWithIndexPath:関数は私のクラスで呼び出されていません。TableviewDelegateおよびTableviewDatasourceデリゲートです。

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"reaching accessoryButtonTappedForRowWithIndexPath:");
    [self performSegueWithIdentifier:@"modaltodetails" sender:[self.eventsTable cellForRowAtIndexPath:indexPath]];
}

NSLog がコンソールに出力されないため、関数が呼び出されていないと思われます...これはもちろん、セルを選択したときです。以下のスクリーンショットは、セルのセットアップ方法を示しています。

ここに画像の説明を入力

4

8 に答える 8

62

tableView:accessoryButtonTappedForRowWithIndexPath:の行にアクセサリ ビューが設定されている場合、メソッドは呼び出されないとドキュメントに記載されていindexPathます。このメソッドは、プロパティが有効な場合にのみ呼び出され、accessoryViewプロパティをnil使用および設定しaccessoryTypeて組み込みアクセサリ ビューを表示する場合にのみ呼び出されます。

私が理解しているように、accessoryView相互accessoryTypeに排他的です。を使用するaccessoryTypeと、システムは期待どおりに呼び出しtableView:accessoryButtonTappedForRowWithIndexPath:ますが、それ以外の場合は自分で処理する必要があります。

Apple がこれを行う方法Accessoryは、SDK のサンプル プロジェクトに示されています。cellForRowAtIndexPathdataSource デリゲートのメソッドで、ターゲット/アクションをカスタム アクセサリ ボタンに設定します。indexPathをアクションに渡すことができないため、補助メソッドを呼び出して対応するものを取得しindexPath、結果をデリゲート メソッドに渡します。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ...

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    ...

    // set the button's target to this table view controller so we can interpret touch events and map that to a NSIndexSet
    [button addTarget:self action:@selector(checkButtonTapped:event:) forControlEvents:UIControlEventTouchUpInside];
    ...
    cell.accessoryView = button;

    return cell;
}


- (void)checkButtonTapped:(id)sender event:(id)event{
    NSSet *touches = [event allTouches];
    UITouch *touch = [touches anyObject];
    CGPoint currentTouchPosition = [touch locationInView:self.tableView];
    NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint: currentTouchPosition];
    if (indexPath != nil){
        [self tableView: self.tableView accessoryButtonTappedForRowWithIndexPath: indexPath];
    }
}

何らかの理由で、あなたの設定はaccessoryViewのケースに当てはまるようです。accessoryTypeInterface Builder を使用する代わりに with コードを設定しようとしましたか?

于 2012-10-10T01:14:15.813 に答える
7

セルをクリックして選択しただけですか、それとも実際にセルのアクセサリ ボタン インジケーターをクリックしましたか? あなたの質問からは明らかではありません。

accessoryButtonTappedForRowWithIndexPathセルを選択したときではなく、セル内のボタン アイコンをクリックしたときに適用されます。

于 2012-09-06T09:57:26.680 に答える
2

描いたのはスポットです。

Storyboard で「DetailDisclosure」に変更すると、メソッドが起動します。(xコード 4.6 DP3)

于 2012-12-10T20:57:26.723 に答える
0

これは、ストーリーボードを使用して開示ボタンを処理する別の方法です。テーブル ビュー セルをクリックして、[接続インスペクター] に移動する必要があります。Triggered Segues というセクションがあり、選択行からセグエ先の UIViewController にドラッグできます。セグエは自動的に発生し、prepareForSegue をキャプチャして、発生したときに通知をキャプチャできます。
関数 accessoriesButtonTappedForRowWithIndexPath が開示ボタンに対して呼び出されることはありません。詳細開示ボタンに対してのみ呼び出されます。

于 2015-01-25T00:25:53.007 に答える