2010-06-28 34 views
1

通行證數據

(從this thread續)假設我有以下視圖中創建:

http://cl.ly/1USw/content

「查看」按鈕應該推送新的ViewController其將按Josh或Al顯示所有照片,具體取決於按下哪個按鈕。

我的問題是

在視圖控制器代碼,我怎麼確定哪些「查看」按鈕被按下(頂部或底部)?

這是代碼,我有:

- (IBAction) viewImageList { 
    PhotoListViewController* photoListViewController = [[PhotoListViewController alloc] 
                 initWithNibName:@"PhotoListViewController" 
                 bundle:[NSBundle mainBundle]]; 

    // here, I want to dynamically pass in the name (Josh or Al) based on which 'View' button is pressed 
    photoListViewController.ownerName = @"someName"; 

    [[self navigationController] pushViewController:photoListViewController animated:YES]; 
    [photoListViewController release]; 

} 

或者,如果任何人有不同的方法,我想聽聽吧:)

回答

2

你IBAction爲應該接受一個指向事件的發件人: (IBAction)viewImageList:(id)sender 您可以檢查發件人的tag財產,或保持一個數組按鈕並將發件人的身份與數組中按鈕的身份進行比較,以查看發生點擊的位置。

1

如果這些按鈕的觸摸的內心去行動相同的IBAction爲方法調用,可以將每個按鈕的標籤值設置爲唯一代碼或Interface Builder的東西,然後判斷髮送者的價值,但加入:像

  • (IBAction爲)viewImageList(ID)發件人:(我d)發件人{[sender isKindOfClass:[UIButton class]]){ uIButton btn =(UIButton)sender; 開關(btn.tag){ ...