gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 03:28:02 26 4
gpt4 key购买 nike

要获取位于导航 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com