我有一个核心数据中所有实体的列表视图。
当点击时,它应该将所选实体的值推送到即将被推入导航堆栈的视图中的文本字段中,但它不会。
令我感到困惑和烦恼的是,如果我使用NSLog
,它会记录,但我使用相同的代码并且不会将相同的信息输出到textFields
。标题也应该改变,它让我感到困惑的是为什么文本字段不会。我错过了什么吗?我是否错误地访问了运动员实体?
以下是我的代码段(注意Athlete.h
是动态创建核心数据属性,AllAthletes.h
是table view
,AthleteDetail.h
是推送的详细视图)
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];
}
答案 0 :(得分:2)
为AthleteDetail AthleteDetail *athleteDetail= [self.storyboard instantiateViewControllerWithIdentifier:@"showAthlete"];
创建对象时,它不会初始化所查看的控件。
获得所需行为的最佳方法是在AthleteDetail类中创建名为“athleteName”的属性
@property(nonatomic, strong) NSString * athleteName
现在而不是athleteDetail.firstDetailTextField.text = athlete.first;
写下面的代码
athleteDetail.athleteName = athlete.first;
现在在AthleteDetail类的viewDidLoad中,将athleteName分配给您的文本域
firstDetailTextField.text = _athleteName;
我希望这对你有用.. :))