Iphone 用数据加载新视图-不';不替换字符串
点击UITableView中的某些行后,应用程序将进入新屏幕。我可以在打开时替换此屏幕中UIImageView中的图像,但我在其中定义了无法替换的NSString。不知道为什么。这个NSString只是在screenView类的file.h中定义为带有@property(非原子,retain)的NSString 为什么它不想为NSString赋予一个新值,而可以用这种方式替换图像?试试看Iphone 用数据加载新视图-不';不替换字符串,iphone,objective-c,ios,xcode,Iphone,Objective C,Ios,Xcode,点击UITableView中的某些行后,应用程序将进入新屏幕。我可以在打开时替换此屏幕中UIImageView中的图像,但我在其中定义了无法替换的NSString。不知道为什么。这个NSString只是在screenView类的file.h中定义为带有@property(非原子,retain)的NSString 为什么它不想为NSString赋予一个新值,而可以用这种方式替换图像?试试看 - (void)tableView:(UITableView *)tableView didSelectRo
- (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
}
您使用哪种方法记录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];
}
编译器是否给了您一个错误(在这种情况下,错误是什么?)或者是某种运行时问题?不,没有错误。就在我在screenView类中使用字符串值调用NSLog时,它显示为(null)。能否显示相关的定义/合成和NSLog行?在screenView h中:<代码>@interface ScreenView:UIViewController{IBOutlet UIImageView*imageView;NSString*MyString;}@property(非原子,保留)IBOutlet UIImageView*imageView@属性(非原子,保留)NSString*MyString代码>和NSLog(@“%@”,MyString);我当然有我的字符串。显然,类ScreenView是作为UITableView类中的对象ScreenView加载的。正如我所说,它对图片有效。好吧,我明白为什么它不起作用了。我在vievDidLoad中调用了NSLog,因此它向我显示了一个默认值(尚未替换)。我需要在ViewDid中调用它来显示这个正确的-changed.Correct。就是这样。我发现了它,直到你写了,但是谢谢:)我喜欢viewDidLoad中的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];
}