代码之家  ›  专栏  ›  技术社区  ›  William Hu

UITableView故障

  •  0
  • William Hu  · 技术社区  · 15 年前

    我的导航控制器的根视图控制器是uiviewcontroller(root viewcontroller)。 它包含一个UITableView,如下所示: alt text http://www.freeimagehosting.net/uploads/c9b0985b63.png

    当我按下箭头按钮(调用rootviewcontroller中的函数)时,TableView将向左移动,直到左边只有箭头按钮。

    但现在我还想按这个单元格来实现相同的功能。但问题是方法didselectrowatindexpath:无法在rootviewcontroller中调用该函数。那么该怎么做呢?

    我想使用addobserver方法,但对此一无所知,任何人都可以解释或给我一些想法,非常感谢!

    1 回复  |  直到 11 年前
        1
  •  0
  •   William Hu    11 年前

    两种方式: 1.使“地图”视图控制器成为导航视图控制器的委托。然后在

    didSelectRowAtIndexPath:
    

    打电话给 [delegate buttonPressed]; 2。第一次按下按钮时,添加观察者:

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

    然后,当按下单元格时,发布通知点:

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

    把观察者移到 dealloc 方法:

    [[NSNotificationCenter defaultCenter] removeObserver:self];