How to set property on Storyboard UIViewController between segues on iOS 5?
I'm trying to set a simple image to a UIImageView as such when a button touches the first view:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
ImageViewController *imageViewController = [segue destinationViewController];
imageViewController.title = @"test";
imageViewController.imvBig.image = [UIImage imageNamed:@"test.png"];
imageViewController.lblTest.text = @"test2";
}
The .title is installed and displayed just fine, but for some reason I cannot get imvBig.image to display and I cannot get the label text. Yes, I have a property created with Outlet, etc. (Since I just dragged it from IB right into the code and it was autoaccided).
Can anyone tell me how to properly set a property from one regular view to the next in a storyboard setup?
source to share
Probably ImageViewController
not uploaded his ideas from the storyboard, but when the system sends prepareForSegue:sender:
, so these outputs ( imvBig
and lblTest
) are zero. Messages sent to nil are silently ignored.
It is generally not recommended that a source view controller is fired with destination manager views. The target view controller must set these view options, typically to viewDidLoad
, viewWillAppear:
or viewDidAppear:
.
source to share
It looks like I was able to get this to work by creating an NSString property and then setting the label to string in the viewDidLoad from ImageViewController:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.lbltest.text = _myString;
}
I think I cannot set the property directly until the view is loaded.
source to share
You don't need the viewController to just use the segue property of the destinationViewController. I always set the id in the storyboard, so I can use multiple segues:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"Show ImageViewController"]) {
[segue.destinationViewController setTitle:@Test"];
[segue.destinationViewController setFoo:@"Bar"];
//More stuff to set
}
}
also create an image in ImageViewController as a property and synthesize it and then set it as an image in viewDidAppear:
self. imvBig.image = myNewImge;//this in the viewDidLoad
And set this image in the segment:
[segue.destinationViewController setMyImage:[UIImage imageNamed@"test.png"]];
source to share