2010-05-19 72 views
0

我的導航控制器的根視圖控制器是UIViewController(rootViewController)。 它包含的一個UITableView,如下: alt text http://www.freeimagehosting.net/uploads/c9b0985b63.pngUITableView問題

當我按下箭頭按鈕(下稱RootViewController的功能),將實現代碼如下會向左移動,直到只剩下在左邊的箭頭按鈕。

但現在我也想按下單元格來使相同的功能。但問題是didSelectRowAtIndexPath方法:無法在rootViewController中調用該函數。那麼應該怎麼做呢?

我想使用addObserver方法,但對此一無所知,任何人都可以解釋或給我一些想法,非常感謝!

回答

0

兩種方式: 1.製作「地圖」視圖控制器是導航視圖控制器的代表。然後在

didSelectRowAtIndexPath: 

呼叫[delegate buttonPressed]; 2.當按鈕被按下首次添加的觀察者:

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

然後當按下電池,張貼notificatoin:

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

並刪除觀察者dealloc方法:

[[NSNotificationCenter defaultCenter] removeObserver:self];