Vjardel
Vjardel

Reputation: 1075

Passing data with Unwind segue UITextField

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

Upvotes: 0

Views: 142

Answers (1)

rdelmar
rdelmar

Reputation: 104082

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.

Upvotes: 1

Related Questions