iphone - 子类 UIViewController 以编程方式创建列表而不使用 nib

标签 iphone ios

我目前需要的是通过子类化 UIViewController 并在不使用任何 nib 文件的情况下应用必要的方法,以编程方式创建一个 tableview。它可能需要一个 UINavigationViewControlloer。我基本上了解所有这些概念,甚至几乎知道如何将所有内容拼凑在一起,但缺少一些东西。它将有 4 个文件。 AppDelegate h/m 和 SomeNameViewcontroller h/m。我认为 SomeNameViewController 应该有一个属性 UITableView*

我已经尝试了几种方法并在网上查看,但我一直收到带有导航栏的黑屏。令人难以置信的令人沮丧,当我可以让 tableView 显示时,我无法让 tableView 重新加载数据:/

最佳答案

从您的叙述来看,您似乎没有完全掌握所涉及的概念。例如,没有 UINavigationViewController 这样的东西。 .以下是您需要知道的:

  • 一个 UINavigationController是 View Controller 的 Controller 。

  • 您可以在您的应用委托(delegate)中创建它
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:
       yourRootViewController];
    

    并使用 self.navigationController 从 View Controller 访问它.
  • 为了您的目的,您创建了 UITableViewController 的子类。 . Xcode 中的模板应该已经有所有 datasource 的 stub 。和 delegate你需要的方法。
  • 在您的应用委托(delegate)中,确保您已将正确的导航 Controller 分配为根。

  • application:didFinishLaunchingWithOptions: :
    self.window.rootViewController = nav; // the nav controller you created
    [nav release];
    [self.window makeKeyAndVisible];
    return YES;
    

    关于iphone - 子类 UIViewController 以编程方式创建列表而不使用 nib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7292743/

    相关文章:

    iphone - 不断从 UITextview 保存文本

    iOS 10 无法打开 Spotify 应用

    ios - sprite-kit 中的简单组合乘数

    ios - CloudKit 在用户之间共享私有(private)容器

    iphone - 单击按钮时根据字母或数字顺序对 UITableView 进行排序

    iphone - 在越狱 iPhone 上测试应用程序

    ios - AWS Cognito - 如何更新经过开发人员身份验证的用户 token ?

    ios - Xcode 6 工具链构建错误

    ios - 在 iOS 上运行 ionic 应用程序时出现 NSURLConnection 错误 1100

    iphone - 将我的 iOS 应用程序分发给测试人员的最佳方式?