I have this problem:
I have two ViewControllers.
I am transitioning to the second view with Segue.
User enters his name on first view controller and taps on a button. If the text is nil, it should not show the second view controller. If some text is there on the text field - it has to show the next view controller.
I am checking the text length here below. As I have only one segue... I am not checking segue identifier.
And, on Storyboard, I have give modal transition CoverVertical. The animation is not working. View is just appearing. UIModalTransitionStyle also I tried. Still not working (on device and simulator)
-(BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
{
if(playerNameTextField.text.length == 0)
{
UIColor *tempColor=UIColorFromRGB(0xFF4981);
[self colorizeTextViewForAWhile:playerNameTextField withUIColor:tempColor animated:YES];
return NO;
}
return YES;
}
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:#"segueMoveToHome"])
{
ViewController *vc = (ViewController *)segue.destinationViewController;
vc.playerName=playerNameTextField.text;
}
}
Your code works perfectly. I just reproduced and I've got a transition with CoverVertical.
In Interface Builder, select the Storyboard Segue and be sure that you have:
I'm linking you a mini demo with your code that works.
I have removed the Identifier text and continued. As it was the only segue or any other reason... it was working. If I put the segue... it is not working. :| Not sure. But I have now my app working.
Related
I'm trying to create a manual segue, which happens only if there is a certain conidition (a successful login).
The steps I have followed are these:
1) I've created a button in source viewcontroller, and i connected the button with a drag with the destination viewcontroller.
2) I set the identifier for the segue, calling it login_ok
3) I've created a -(IBAction)buttonPressed:(id)sender
Now, I tried to make an example, to see if the work or not. I wrote:
- (IBAction)buttonPressed:(id)sender
{
BOOL test = false;
if(test == true)
{
[self performSegueWithIdentifier:#"login_ok" sender:self];
}
Theoretically, the segue should not work, because i set test=false, and i said the segue should work only if test=true.
But the segue works and makes me go to the destination viewcontroller.
Why?
If you connected the button with a drag to the destination controller, it should segue anyway.
You need to connect the segue between screens and not from the button to the screen. Then, you can control your segue from the code.
You should define your segue between controllers not from button to the controller. Defining segue between view controllers is more useful than defining segue from any component to a view controller, because when you want to use a condition for any action, you can use these two methods effectively
[self performSegueWithIdentifier:#"segueID" sender:self];
and
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
For example:
- (IBAction)buttonPressed:(id)sender
{
BOOL test = YES;
if(test == YES)
[self performSegueWithIdentifier:#"login_ok" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"login_ok"])
{
YourNextController *controller = [segue destinationViewController];
controller.welcomeText = #"Hi! Test is true congratulations";
}
}
Especially passing data from controller to another one, this way is always useful.
I have a push segue and want to transfer data between views. I need a different way to resign first responder if the user taps the next button in the navigation bar. I have [textField resignFirstResponder]; in the navigation bar button method but for some reason it is called after the next page viewDidLoad.
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:[NSString stringWithFormat:#"thridClubPage"]]) {
thirdClubPage *nextPage = segue.destinationViewController;
nextPage.title = self.navigationItem.title;
nextPage.location = self.collegeString;
nextPage.people = self.membersString;
nextPage.leader = self.presidentString;
nextPage.Email = self.presidentEmailString;
}
}
- (IBAction)finishPage:(id)sender {
[self.presCell.presidentEmail resignFirstResponder];
}
the segue performs without resigning the textField.
A quick solution is to delete the segue from the button in IB and redraw it between the two view controllers. (In other words, when dragging out the segue, don't control-drag from the button, control-drag from the view controller that contains it). Give the segue an identifier, like #"NextSegue".
Now you can control the order of what happens by triggering the segue yourself...
- (IBAction)finishPage:(id)sender {
[self.presCell.presidentEmail resignFirstResponder];
[self performSegueWithIdentifier:#"NextSegue" sender:self];
}
I have a simple app with 2 screens.
When I press a button to go from the first to the second, everything is performed successfully (including animation). However, when I click the back button on the second screen, I get the following warning:
Warning: Attempt to present <getTextViewController: 0x8f6aa30> on <SecondViewController: 0x946cc80> whose view is not in the window hierarchy!
EDIT: Please don't refer me to other questions regarding above warning - I already saw those, and they refer to other issues.
However, it still switches back to the first screen. Yet, the animation of the segue does not perform.
Also: Information (such as inputted text) in the first screen remains when I return to the first screen, while information in the second screen resets every time the screen comes up.
Here is how I call both operations:
Segue from View 1 to View 2:
Name: F21, Style: Modal, Transition: Cross Dissolve, Animation: True.
Segue from View 2 to View 1:
Name: F12, Style: Modal, Transition: Cross Dissolve, Animation: True.
Code in getTextViewController.m (View 1):
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([[segue identifier] isEqualToString:#"F21"]){
UIViewController *v = [segue destinationViewController];
[self dismissViewControllerAnimated:NO completion:nil];
v = self;
}
}
-(void)performSegue:(NSString*)str{
[self performSegueWithIdentifier:str sender:self];
}
//In some other method:
[self performSegue:#"F21"];
Code in SecondViewController.m (View 2):
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([[segue identifier] isEqualToString:#"F12"]){
UIViewController *v = [segue destinationViewController];
[self dismissViewControllerAnimated:NO completion:nil];
v = self;
}
}
-(void)performSegue:(NSString*)str{
[self performSegueWithIdentifier:str sender:self];
}
- (IBAction)goBack:(id)sender {
[self performSegue:#"F12"];
}
I would very much appreciate any help to understand why the first segue works while the second doesn't.
Thank you,
Dean
NOTE: Here is the full project - https://github.com/dean13-meet/firstIOSApp
EDIT: Updated git.
Im not exactly sure what you're trying to do in your prepareForSegue, their is no need to be dismissing VC's there. If you want to have a simple app where you go from VC1 to VC2 and then back again, your best bet is to use a segue and an unwindSegue.
So in your storyboard control drag from a button on VC1 to VC2 and select your segue type. Then in VC1.m setup the unwind segue such as:
- (IBAction)unwindFromViewController:(UIStoryboardSegue *)segue
{
//empty implementation
}
Finally, in your VC2 control drag from the back button to the green exit icon on VC2 and select your unwindFromViewController method.
That should do what you're looking for.
For the sake of simplicity, I would suggest using a push segue opposed to modal because it takes care of all the back buttons for you. If you don't like the idea of a navigation controller however, try dismissing the view with the following: Moving back from a Controller to a previous one
Hello I have a button that must present a modal view controller when tapped
Here is the action:
- (IBAction)addNewLevelAction:(id)sender
{
[self performSegueWithIdentifier:kNewLevelConfigureSegue sender:self];
}
in prepareForSegue:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:kNewLevelConfigureSegue]) {
PSLevelConfigViewController *dest = (PSLevelConfigViewController *)[segue destinationViewController];
dest.delegate = self;
}
}
However when I tapp it I get:
Warning: Attempt to present <PSLevelConfigViewController: 0x98cbd00> on <UINavigationController: 0x98aac70> while a presentation is in progress!
Why is this? There is no other presentation there...
If you perform the segue programmatically, the segue must be connected to the controller and not directly to the button.
Check if your storyboard is set correctly (post some screenshots if you need help).
In such situation, if your segue is connected to the button AND, at the same time, to an action that performs it programmatically, your segue will be performed twice, and the second perform will cause that error.
I am using storyboards with iOS 5 and Xcode 4 and have run into a small problem.
I have a view controller (WallPostViewController) that is the root view controller of my navigation controller. Through the storyboard, I have a segue (called "PushWallPostCommentsSegue") which is performed after the user clicks a button.
When I get to prepareForSegue:sender, I set an object inside the newly pushed view controller.
Code follows:
-(IBAction)addNewCommentButtonTouched:(id)sender {
[self performSegueWithIdentifier:#"PushWallPostCommentsSegue" sender:self];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqual:#"PushWallPostCommentsSegue"]) {
NSLog(#"Pushing from %# to %#", segue.sourceViewController, segue.destinationViewController);
WallPostCommentsViewController* wallPostCommentsViewController = segue.destinationViewController;
[wallPostCommentsViewController setWallPost:wallPostInfo];
[wallPostCommentsViewController setParent:self];
}
}
The problem is: this view controller is never pushed and is automatically deallocated (even though it has connections in the storyboard and it's own other objects).
Btw, this view controller's initWithCoder: method IS called.
Just can't find the problem here. Any heads up?
Thanks in advance, Ricardo P.