0

カスタムセルにボタンがあるテーブルがあります。このボタンを押すと、次のコードを使用してボタンを検出するメソッドが呼び出されます。

NSIndexPath *indexPath = [NSIndexPath indexPathForRow: [[[notification userInfo] valueForKey:@"row"] intValue] inSection: 0];
PlaceRoomCustomCell *cell = (PlaceRoomCustomCell*)[self tableView:self.tableView cellForRowAtIndexPath:indexPath];
for (UIView *view in  cell.contentView.subviews){
    if (view.tag == 1) {
        for (UIView *subview in  view.subviews){
            if ([subview isKindOfClass:[UIButton class]]){
                  [(UIButton *)subview setImage:[UIImage imageNamed:@"placeRoomTableCellLikeButtonRedIcon.png"] forState:UIControlStateNormal];
                  [(UIButton *)subview setImage:[UIImage imageNamed:@"placeRoomTableCellLikeButtonRedIcon.png"] forState:UIControlStateHighlighted];
                  [(UIButton *)subview setImage:[UIImage imageNamed:@"placeRoomTableCellLikeButtonRedIcon.png"] forState:UIControlStateDisabled];

                  NSLog(@"tag %i",subview.tag); //correct
             }
         }
      }
}

タグは正しいですが、画像は変更されていません。

ボタンの id 送信者を直接使用することはできません。というか、使用したくありません。

コードは正しいようです

ありがとう!

4

1 に答える 1

0

通常、UI オブジェクトがコントローラにアクションを送信すると、メソッドが に渡されますが、senderこれは使用できませんか?

たとえば、上記のコードが置かれているメソッドの定義は次のようになります。

-(void)buttonPressed:(id)sender;

ボタンはどこにあるsenderべきか。NSNotifications を使用しているため、質問には他の重要な情報が欠けているのではないかと思いますが...

于 2013-05-19T16:21:27.227 に答える