2013-05-19 23 views
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發送者,或者說,我不喜歡使用它。

該代碼似乎正確

謝謝!

+0

你能確保indexPath是正確的?將您想要更改的按鈕設置爲PlaceRoomCustomCell類中的屬性如何設置? –

+0

indexpath是正確的:它是indexpath.row。 – Vins

+0

我的意思是說:標籤是indexpath.row – Vins

回答

0

正常情況下,任何用戶界面對象發送到控制器的操作,該方法通過sender,你能不能用呢?

例如其中,上面的代碼坐在定義的方法可能是這樣的:

-(void)buttonPressed:(id)sender; 

其中sender應的按鈕。 雖然我有一個鬼鬼祟祟的懷疑,我們缺少的問題,其他一些重要的信息,因爲你正在使用NSNotifications ...

+0

我使用另一個異步方法,在此之後調用。我不直接調用這個方法 – Vins