ios - 如何设置位于导航 Controller 根部的 UITextField 文本?

标签 ios objective-c uiviewcontroller uitextfield

要获取位于导航 Controller 根部的 UIViewController 的引用,我这样做:

UIViewController *root = (UIViewController *)[self.navigationController.viewControllers objectAtIndex:0];

获得该引用后,如何在该 Root View 上的 UITextField 中设置文本?我尝试了以下但它不起作用:

NSString *str = @"";
[[root txtID] setText:str];

Xcode 显示错误:“'UIViewController' 没有可见的@interface 声明选择器'txtID'”。

最佳答案

问题出在这一行:

UIViewController *root = (UIViewController *)[self.navigationController.viewControllers objectAtIndex:0];

您想引用根 Controller 的实际类。像这样的东西:

MyRootViewController *root = (MyRootViewController *)[self.navigationController.viewControllers objectAtIndex:0];

MyRootViewController 替换为您的根 Controller 类的实际名称 - 具有 txtID 属性的那个。

关于ios - 如何设置位于导航 Controller 根部的 UITextField 文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20200911/

相关文章:

ios - 从不同的 ViewController iOS 更新 UITextField

objective-c - 给定年份使用 iPhone SDK 的天数?

ios - 在 Swift 中使用 SoundTouch 框架

IOS 应用程序在后台不会显示推送通知。 swift

ios - 如何在 UICollectionView 上面实现内容 View

iphone - 比 -forwardInspiration : to perform messages on a specific thread 更快的方法

objective-c - 以模态呈现 UIView 不是全屏

ios - 如何在 Swift 中将 UIViewController 添加到 UIScrollView

ios - 将 mergeChangesFromContextDidSaveNotification 触发 fetchedResultsController 的 objectsChanged : delegate methods?

ios - Xcode 6 - Storyboard UINavigation 后退按钮未出现在应用程序中