我有两种观点: View1(商店):存储在NSString中用于显示图像的URL。
View2(ModifyShop):带有来自view1的URL的文本字段。
我可以将数据从view1传递到view2:NSString中存储的URL出现在文本字段中。
现在我想使用view2中的Text字段修改此URL,并修改view1中的NSString。我该怎么做?
这是我的代码:
购物:
- (void)viewDidLoad {
[super viewDidLoad];
[self.modifyButton setHidden:YES];
dispatch_async(dispatch_get_global_queue(0,0), ^{
self.imageButtonURL = @"http://bundoransurfshop.com/wp-content/uploads/2015/02/72-torq-pink.jpg";
imageButtonData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString:self.imageButtonURL]];
if ( imageButtonData == nil )
return;
dispatch_async(dispatch_get_main_queue(), ^{
self.imageButton.imageView.image = [UIImage imageWithData: imageButtonData];
});
});
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"modifyShop"]) {
ShopModify *viewcontroller = (ShopModify *)segue.destinationViewController;
viewcontroller.imageButtonURL = self.imageButtonURL; }
}
-(IBAction)prepareForUnwind:(UIStoryboardSegue *)segue {
NSLog(@"%@", self.imageButtonURL);}
ModifyShop:
- (void)viewDidLoad {
[super viewDidLoad];
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.photoURL.text = [NSString stringWithFormat:@"%@", self.imageButtonURL];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
Shop *viewcontroller = (Shop *)segue.destinationViewController;
viewcontroller.imageButtonURL = self.photoURL.text;
}
这使我的应用崩溃了:
[Reports setImageButtonURL:]: unrecognized selector sent to instance
答案 0 :(得分:1)
错误在于您要在Reports实例上设置imageButtonURL,而不是在Shop上设置您认为目标视图控制器的位置。您的展开似乎是错误的控制器。你必须错误地连接unwind segue。您说您有2个视图(实际上是视图控制器),但您的应用程序中还必须有一个Reports类。