【问题标题】:Embed navigation controller in modal view contriller programatically以编程方式将导航控制器嵌入模态视图控制器
【发布时间】:2015-03-12 03:45:07
【问题描述】:

我正在使用以下代码展示一个模态视图控制器,

[[mInfo objectForKey: kNavigationController] presentViewController:(UIViewController*)modalViewControlr animated:YES completion:nil];

UITableView。在选择表格视图单元格时,我想将其导航到另一个名为 navigatedViewUIView

这可以通过在导航控制器中嵌入自我(即modalViewControlr)并将视图(即navigatedView)添加到视图控制器并呈现它来完成吗? 例如,

// in modalViewControlr
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//

 UINavigationController *passcodeNavigationController = [[UINavigationController alloc] initWithRootViewController:self];
        UIViewController *vc = [[UIViewController alloc]init];
        [vc.view addSubview:self.navigatedView];
        self.navigatedView.frame=vc.view.frame;
 [passcodeNavigationController pushViewController: vc animated:YES];

//

}

请帮忙....

【问题讨论】:

    标签: ios uinavigationcontroller modalviewcontroller


    【解决方案1】:

    我更喜欢这样更容易理解。

    1.在AppDelegate中嵌入navigationController:

    ModalViewControlr *vc = [[ModalViewControlr alloc]init];
    UINavigationController *passcodeNavigationController = [[UINavigationController alloc] initWithRootViewController:vc];
    self.window.rootViewController = passcodeNavigationController;
    

    2.新建类NavigatedViewController并自定义viewDidLoad中的控制器

    创建一个UIView 调用navigatedView

    @property (nonatomic, strong) UIView *navigatedView;
    
    -(void)viewDidLoad
    {
       [super viewDidLoad];
       _navigatedView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
       self.navigatedView.backgroundColor = [UIColor redColor];
       [self.view addSubView:self.navigatedView];
    }
    

    3.然后返回你要推送的modalViewControlr

    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
       NavigatedViewController *vc = [[NavigatedViewController alloc] init];
       [self.navigationController pushViewController:vc animated:YES];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      • 2013-07-28
      • 2017-06-16
      • 1970-01-01
      • 2021-07-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多