【问题标题】:How to design a Navigation-Based app for the iPhone?如何为 iPhone 设计基于导航的应用程序?
【发布时间】:2017-12-17 07:19:13
【问题描述】:

我是一名新的 iPhone 开发人员,正在学习 Objective-C,并尝试使用基于导航的模板构建 iPhone 应用程序。我希望这个应用程序运行的方式是有一个按钮,在按下后将用户带到第二个屏幕。不幸的是,我没有在网上看到任何这样的例子,并且不确定如何做到这一点。

我意识到我不会使用表格视图,我会在其中选择特定的行,然后将我带到另一个屏幕。什么视图适合在第一个屏幕上有一个按钮,可能还有一个搜索栏,然后我可以导航到第二个屏幕?我需要第二个屏幕有一个表格视图,其中包含从 sqlite 数据库中检索到的行列表。当按钮被选中(即触发事件)时,我将使用 RootViewController(即第一个屏幕)中的什么方法来放置要执行的代码?

【问题讨论】:

    标签: iphone objective-c


    【解决方案1】:

    不确定我是否正确理解了您的问题,但是...

    在 RootViewController 中:

    - (void) viewDidLoad
    {
      UIButton* button = [UIButton buttonWithStyle:...];
      [button setFrame:CGRectMake(0, 0, 10, 10)];
      [button addTarget:self action:@selector(onButtonPressed) forControlEvents:UIControlEventTouchUpInside];
      [[self view] addSubview:button];
    }
    
    - (void) onButtonPressed
    {
      SecondViewController* controller = ...;
      [[self navigationController] pushViewController:controller animated:YES];
    }
    

    addTarget:action:forControlEvent: 选择器注册每次按下按钮时都应调用的“回调”。在回调 (onButtonPressed) 中,您只需创建新控制器并将其推送到导航控制器中。

    通常您应该在 Interface Builder 中执行此操作。只需添加 IBAction 并将其连接到事件。

    【讨论】:

    • 非常感谢您的及时回复,您的解决方案有效!保重。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多