简体   繁体   中英

how to pass image from view controller to tab bar with segue?

I am at a loss as to how to pass a selected image in one view controller to a tab bar controller using a segue, i keep on getting "unrecognized selector sent to instance ...". Here is my prepare for segue in a ViewController3 :

 if ([[segue identifier]isEqualToString:@"tabbarGo"]) {

    UITabBarController *tabar=segue.destinationViewController;
    UINavigationController *navController = [tabar.viewControllers objectAtIndex:1];
    ViewController5 *fifthView=[navController.viewControllers objectAtIndex:0];

    fifthView.theImage = selectedImage.image;

    [tabar setSelectedIndex:1];
}

i have imported ViewController5 into ViewController3 as 5 is the tab bar controller and the m file for viewcontroller5 is as follows :

#import <UIKit/UIKit.h>
#import "ViewController5.h"
#import "ViewController3.h"
@interface ViewController5 ()
@end

@implementation ViewController5

@synthesize theImage;
-(void)setImage:(UIImage *)image
{
}
- (void)viewDidLoad {

[super viewDidLoad];

[_imageView setImage:theImage];

}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end

I do not understand what i am doing wrong and have gone through most of the posts, or should i go through a "NSUserDefaults *prefs" approach to this ? Any help appreciated and thanks.

ok got it to work to send an image to a tab bar with navigation controller by adding one line of code, i was forgetting to specify the NSString value of the segue so here is the final full code for "prepare for segue" :

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSString * segueIdentifier = [segue identifier];
 UITabBarController *tabar=segue.destinationViewController;
UINavigationController *navController = [tabar.viewControllers objectAtIndex:1];
ViewController5 *fifthView=[navController.viewControllers objectAtIndex:0];
fifthView.theImage = selectedImage.image;
[tabar setSelectedIndex:1];        
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM