代码之家  ›  专栏  ›  技术社区  ›  JamesSugrue

带uiTableView和uiView的uiAvigationController

  •  1
  • JamesSugrue  · 技术社区  · 16 年前

    我希望能够在父视图中的uiTableView和标准uiView之间切换。基本上,我有一个UITableView,它在加载时显示一个信息日志。我想在窗口的头部有一个段控件,当用户点击时,它将转换为一个图形视图,这是一个标准的uiview。

    有问题的uiviewcontroller需要能够从rootviewcontroller堆栈推送。

    我试过很多方法,但似乎都做不到。是否有人对如何实现这一点有任何代码示例或建议?

    3 回复  |  直到 14 年前
        1
  •  0
  •   Andrew Grant    16 年前

    听起来您应该有一个父视图,其中包含段控件和子视图的空间。当用户选择段时,您将添加相关视图(表或图)作为视图的子视图,并设置其矩形,使其占据子区域。

    -----------
    | Segment |
    -----------
    |         |
    |         |
    |  Child  |
    |         |
    -----------
    
        2
  •  0
  •   Drew C    15 年前

    您完全不必更改uiviewController即可在导航控制器中显示它。分段控制器应调用执行以下代码的方法:

    UIViewController *myViewController = [[UIViewController alloc] init];
    [self.navigationController pushViewController:myViewController animated:YES];
    [myViewController release];
    

    我没有链接到一个例子,但是如果需要,我可以回答更多的问题。

    德鲁

        3
  •  0
  •   JamesSugrue    14 年前

    其实并不像最初看起来那么困难。基本上,如果你有一个空视图的parentviewcontroller和一个顶部的navcontroller。将航段控制置于导航控制器的中心视图中。

    然后,您只需在段控件更改时切换ViewController视图。唯一要做的就是保留一个指向当前视图的指针,并在将新视图添加到parentvc之前删除它。代码如下:

    - (void)showView
    {
        if (_currentView != nil)
            [_currentView removeFromSuperview];
    
        if (segmentControl.selectedSegmentIndex == 0)
        {
            if (_graph == nil)
                _graph = [[DrawGraphViewController alloc] initWithNibName:@"DrawGraphViewController" bundle:[NSBundle mainBundle]]; 
    
            self.navigationItem.rightBarButtonItem = nil;
            _currentView = _graph.view;
    
            [contentView addSubview:_graph.view];
            [_graph reloadGraph];
        }
        else if (segmentControl.selectedSegmentIndex == 1)
        {   
            if (_log == nil)
                _log = [[LogTableViewController alloc] initWithNibName:@"LogTableView" bundle:[NSBundle mainBundle]];
    
            self.navigationItem.rightBarButtonItem = self.editButtonItem;
            _currentView = _log.view;
            [contentView addSubview:_log.view];
            [_log loadData];
        }   
        else {
            if (_export == nil)
                _export = [[ExportViewController alloc] initWithNibName:@"ExportView" bundle:[NSBundle mainBundle]];
    
            _currentView = _export.view;
            [contentView addSubview:_export.view];
        }
    }