IOS segue is not working when clicking on an Image - ios

I have a view with an Image View, when the user clicks on it, I want to load the image inside it in a separate view.
This is my segue:
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:#"Show Player Information"]){
if ([segue.destinationViewController isKindOfClass:[PlayerViewController class]]){
PlayerViewController *playerViewController = (PlayerViewController*)segue.destinationViewController;
[playerViewController setPlayer:[self.team.players objectAtIndex:self.tableView.indexPathForSelectedRow.row]];
}
}else if([segue.identifier isEqualToString:#"Show Image"]) {
if ([segue.destinationViewController isKindOfClass:[ImageViewerViewController class]]){
ImageViewerViewController *imageViewerViewController = (ImageViewerViewController*)segue.destinationViewController;
[imageViewerViewController setImageName:#"France.jpg"];
}
}
}
But nothing happens when clicking on the image view though the segue has the correct identifier.
Please check the below screenshot
Could you help me please?
I appreciate your time and efforts.
Regards,

Although it is possible to perform a segue from a UIImageView (although not directly from IB) in my opinion is much simpler to just replace it with a UIButton and set its image instead.
Then, based on your posted code, you could just remove your old segue, ctrl+drag from the button to your destination controller, choose 'push' and then set the segue identifier to Show Image.
It should be noted here that UIImageView (unlike its ancestor UIView) has its userInteractionEnabled property set to NO by default (more about it here). So if you choose to handle any events directly from the UIImageView make sure that you switch it to YES (here is a similar answer regarding this).

Related

Xcode segue with an UIImageView

In Xcode I can control + mouse drag from a UIButton to another UIViewController, in order to enable that button to segue to that UIViewController when a user presses the button, how can I recreate this property for UIImageView ?
I tried changing its traits to Button [Check] and User Interaction Enabled [Check], plus enabling Accessibility, and Enabling User Interaction in the Attributes Inspector, however still, nothing happens when I control + mouse drag from a UIImageView to another UIViewController.
If possible* I would appreciate a solution that doesn't involve code.
*Objective-C
Use a button.
Assign a image to the button. then make the segue
You can not add segue on UIImageView. Add segue from your UIImageView's view controller to your destination view controller. Give tap gesture to your UIImageView, in action method of tap gesture use perform segue method.
See below code
-(void)tapHandeler:(UITapGestureRecognizer*)guesture
{
[self performSegueWithIdentifier:#"YOUR SEGUE IDENTIFIER" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([segue.identifier isEqualToString:#"YOUR SEGUE IDENTIFIER"]) {
// If you want to do any preprocessing, do here
}
}

IOS - Use Segue identifier in child method

This is probably a basic question - but I cant seem to find the answer to it in my searches!
I have a uiview setup which contains two input areas which are linked to a child modal view via separate segues.
this is my parent prepare for segue method -
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"goalInfo"])
{
[segue.destinationViewController setYourGoalViewController:self];
}
if ([segue.identifier isEqualToString:#"longGoalInfo"])
{
[segue.destinationViewController setYourGoalViewController:self];
}
}
basically i'd like to determine which segue had been used in the child view so I can apply the relevant filed updates and alter a title/description in the child view. - I basically need something very similar to
if ([segue.identifier isEqualToString:#"goalInfo"])
but i'm not sure how to access this from teh child? Any tips?
The segue identifier is check on the source ViewController during its prepareForSegue: method. What you rather need is during prepare for segue is to set properties on the destination viewController and then when it loads, read these properties and set UI outlets.
Look at this example: I am stuck at presenting a full image on tapping the cell in UICollectionViewController. It's about CollectionVC and its detailVC, but the principle is the same.

iOS Storyboard Passing Data

Is there anybody who can help a beginner?
I've got two storyboards, the first has a button and the second has a label. I want to push the button and I want the label to display the text.
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
second *myVC = segue.destinationViewController;
myVC.mylabel.text = #"Why isn't this working!!";
}
The button acts as the segue.
I would also like to add that I've checked everything and I'm puzzled as to know why it's not working. I would have expect it to work, so if someone could also explain what I'm doing wrong or missing I'd be very grateful.
Thank you for your help.
In prepareForSegue: your second view does not exist yet. The output of mylabel is not connected with the view. Create a new NSString property in your second controller. Set it in prepareForSegue: and use it to setup the label in viewDidLoad: of the second controller.

Different UIViewController modal transition to another VC with different animation

here is my question, let s say i have UIViewController A B C D...
currently I am using the default transiation animiation for all VCs modal transite , shows as ->
what i want is... let user pick what kind of transiation animation they like to use..for all the VC modal transition animations...
i guess some code need to be added in some where here? ->
- (IBAction)cardAction:(id)sender {
UIImage *img = [(UIButton *)sender currentBackgroundImage];
[self performSegueWithIdentifier:#"cardSegue" sender:img];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:#"cardSegue"]) {
UIImage * img = (UIImage *)sender;
ResultViewController *viewcontroller = [segue destinationViewController];
viewcontroller.img = img;
}
}
please help..
A segue lets you define the transition in the Storyboard but you want to let the user define the transition. UIStoryboardSegue doesn't let you do this, so you're going to need to perform the transition yourself.
There's a good answer on performing transitions using different styles here:
How to change the Push and Pop animations in a navigation based app
Instead of calling performSegueWithIdentifier, you'd use the code from that answer to perform the transition.
You can just create your own segue subclass and then changing the
- (void) perform;
function.
If you need an example for the segue subclassing go to this tutorial:
>>> Link to tutorial <<<
Regards,
Nils

Conditional Segue navigation from UITableViewCell based on response to UIAlertView

My problem seems like a generic problem, yet can't seem to find an answer for it.
I have a situation where when the user taps on a custom UITableViewCell, I would like to display an alert and then based on the response to the alert, either stay on the same view (user selecting cancel) or display another view (if the user selects proceed). And I would like to do this using the storyboard feature & segues.
How would one go about this? Do you have to do this the old fashioned way?
#user, Just create the alertView the old fashion way; I do know of any storyboard feature to do this differently. Where storyboard can help is with the segues. You can call the segues programmatically. With you alert view cancel button you can just return (i.e. do nothing). For the other option, to display another view, you can programmatically call a segue to transition to the desired view. If you don't have the proper segue already defined for some other reason on your storyboard, just create a button out and use that to create the segue and name it. Name the segue by clicking on it in storyboard and use the attributes inspector to give it name (identifier). Then hide the button or put it out of the view. I typically put these type of button on the toolbar and use spacers to keep them out of the view. Here's some sample code:
Call the segue from the alert view delegate like this:
[self performSegueWithIdentifier: #"done" sender: self];
Also implement this method to do any necessary task to prepare for the segue:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"done"])
{
// [[segue destinationViewController] setManagedObjectContext:self.managedObjectContext];
// [[segue destinationViewController] setSelectedClient:selectedClient];
}
}
You can create segues directly from the startingViewController to multiple destinationViewControllers that can then be "performed" programmatically. You do not need to create any hidden buttons for them, which does seem like a hack.
OK I came up with a solution in keeping with the storyboard that I like.
Example:
My tableview has 2 sections, grouped, and cells are dynamic prototype. Section 0 contains one row/UITableViewCell & I don't want it to segue. Section 1 contains multiple cells that I want to trigger the segue & drill down into the detail.
In Storyboard:
I removed the segue linking the tableviewcell to the destination view controller.
I made a 'generic' segue linking the source view controller directly to the destination view controller.
In the attributes on the segue, I set the identifier ('EditTimePeriod') and set the type to Push (I presume Modal would work just the same).
In the source view controller:
In the prepareForSegue method I handled both the common 'AddTimePeriod' segue I control-dragged from my UIBarButtonItem (Add), along with the 'generic'(vc-->vc) 'EditTimePeriod' segue.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// handle the click of the 'Add' bar button item
if([segue.identifier isEqualToString:#"AddTimePeriod"]) {
TimePeriodViewController* tpvc = (TimePeriodViewController*)segue.destinationViewController;
tpvc.delegate = self;
// database & entity stuff for adding the new one to the mOC, etc
}
// handle the click of one of the 'editable' cells -
if([segue.identifier isEqualToString:#"EditTimePeriod"]) {
TimePeriodViewController* tpvc = (TimePeriodViewController*)segue.destinationViewController;
tpvc.delegate = self;
TimePeriod * newTP = [self.timePeriodArray objectAtIndex:self.tableView.indexPathForSelectedRow.row];
tpvc.timePeriod = newTP;
}
}
Then I implemented the tableView:didSelectRowAtIndexPath method, and put my condition in here. If the selected row was outside of section zero I called the EditTimePeriod segue manually, defining the sender as the selected tableviewcell:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(self.tableView.indexPathForSelectedRow.section!=0){
[self performSegueWithIdentifier:#"EditTimePeriod" sender:[tableView cellForRowAtIndexPath:indexPath]];
}
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
return;
}
would be nice to code the cell in section 0 so that it is not selectable in the first place!
Hope this helps though.
** and then 5 minutes later I took another look and realized I could just move the data from section 0 into the section header, which is more intuitive and wasn't being used anyway. leaving the design open for a standard segue from each tableviewcell without needing any condition/check. Was a good exercise anyway though :)

Resources