0

I have two views : View1 (Shop) : URL stocked in NSString for displaying image.

View2 (ModifyShop) : Text field with URL from view1.

I can pass data from view1 to view2 : The URL stocked in NSString appears in Text field.

Now I would like to modify this URL with Text field from view2 and that modify the NSString in view1. How can I make that ?

Here is my code :

Shop:

- (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;
}

That makes my app crashes :

[Reports setImageButtonURL:]: unrecognized selector sent to instance
Vjardel
  • 1,065
  • 1
  • 13
  • 28

1 Answers1

1

The error is saying that you are tying to set imageButtonURL on an instance of Reports, not on Shop which is what you think your destination view controller is. It appears that your unwind is going to the wrong controller. You must have hooked up the unwind segue incorrectly. You say that you have 2 views (view controllers actually), but you must also have a Reports class in your app.

rdelmar
  • 103,982
  • 12
  • 207
  • 218
  • Yeah, I've another view "Reports", but where can I change that ? – Vjardel Mar 20 '15 at 16:29
  • @Viny76, You need to delete the unwind segue, and remake it to the correct controller. Do you also have a method, prepareForUnwind:, in Reports? If so, you should rename it, so you don't have two methods with the same name in two different controllers. – rdelmar Mar 20 '15 at 16:31
  • Thank you for you reply, yes, I've two prepareForUnwind, one in Reports, and one in Shop. How can I specify what's the good I want ? – Vjardel Mar 20 '15 at 16:32
  • @Viny76, you rename one of them like I said. That way, when you make the segue, you will see two different choices as to where to go back to, and you can choose the correct one. – rdelmar Mar 20 '15 at 16:34
  • Yeah, it's now great for Unwind segue, that change my self.imageButtonURL to the UIText Field from view2. But I would like that save for ever this URL text. How can I make that ? – Vjardel Mar 20 '15 at 16:44
  • @Viny76, that's a completely different question, so you might need to ask another question if you need more help with that. If by "forever", you mean that the new URL will persist between launches of your app, you should save it in NSUserDefaults. – rdelmar Mar 20 '15 at 16:50