gpt4 book ai didi

ios - 将文本添加到非事件 View Controller 的文本字段

转载 作者:行者123 更新时间:2023-11-28 22:28:54 25 4
gpt4 key购买 nike

我有一个来 self 的核心数据的所有实体的 ListView 。

点击时,它应该将所选实体的值推送到即将推送到导航堆栈的 View 中的文本字段中,但事实并非如此。

让我感到困惑和恼怒的是,如果我使用 NSLog,它会记录,但我使用相同的代码,它不会将相同的信息输出到 textFields。标题也会按应有的方式更改,这让我感到困惑,为什么文本字段没有。我错过了什么吗?我是否错误地访问了 Athlete 实体?

这是我的代码片段(注意Athlete.h是动态创建的核心数据属性,AllAthletes.h表格 View AthleteDetail.h 是被推送的详细 View )

allathletes.h

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
Athlete *athlete = (Athlete *)[athleteArray objectAtIndex:indexPath.row];
AthleteDetail *athleteDetail= [self.storyboard instantiateViewControllerWithIdentifier:@"showAthlete"];
athleteDetail.firstDetailTextField.text = athlete.first;
athleteDetail.title = athlete.full;
NSLog(@"Full Name: %@",athlete.full);
NSLog(@"Parent's Full Name: %@", athlete.pfull);
NSLog(@"Number: %@",athlete.phone);
NSString *firstNameText = athleteDetail.firstDetailTextField.text;
firstNameText = [NSString stringWithFormat:@"%@",athlete.first];
[self.navigationController pushViewController:athleteDetail animated:YES];
}

最佳答案

当您为 AthleteDetail AthleteDetail *athleteDetail= [self.storyboard instantiateViewControllerWithIdentifier:@"showAthlete"]; 创建对象时,它不会初始化 subview 的控件。

获得所需行为的最佳方法是在 AthleteDetail 类中创建一个名为“athleteName”的属性

@property(nonatomic, strong) NSString * athleteName

现在代替 athleteDetail.firstDetailTextField.text = athlete.first;编写如下代码

athleteDetail.athleteName = athlete.first;

现在在 AthleteDetail 类的 viewDidLoad 中,将 athleteName 分配给您的文本字段

firstDetailTextField.text = _athleteName;

我希望这对你有用..:)

关于ios - 将文本添加到非事件 View Controller 的文本字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18056952/

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