点击UITableView应用中的某些行后,转到新屏幕。我可以替换,例如UIImageView中的图像在这个屏幕上打开,但我定义的还有NSString,它无法替换。不知道为什么。这个NSString只是在screenView类的文件.h中定义为带有@property的NSString(非原子,保留)。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.navigationController pushViewController:self.screenView animated:YES];
self.screenView.title = @"Screen Name";
self.screenView.imageView.image = MyImage; // this work
self.screenView.MyString = @"Work?"; // but this not
}
为什么它不想为NSString赋予新值,而图像可以用这种方式替换?
答案 0 :(得分:1)
您在哪种方法中记录MyString?
我假设您在显示或加载视图时执行此操作,这意味着它将不包含值,因为您在推送后设置它。
我建议尝试:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
self.screenView.title = @"Screen Name";
self.screenView.imageView.image = MyImage; // this work
self.screenView.MyString = @"Work?"; // but this not
[self.navigationController pushViewController:self.screenView animated:YES];
}
答案 1 :(得分:0)
TRY
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.navigationController pushViewController:self.screenView animated:YES];
self.screenView.title = @"Screen Name";
self.screenView.imageView.image = MyImage; // this work
self.screenView.MyString = [[NSString alloc]initWithString:@"Work?"];
//self.screenView.MyString = @"Work?"; // but this not
}