2010-05-19 75 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];