I have an app having 7 screen. On the screen 7 i have a button that does valiation and submits data and then it jumps to screen 1 using modal segue.
But ,I only want to move screen1 if the validation succeeds or else i dont want to move to screen1.
Currently its moving to screen 1 independent of validation.
button click code is as below
- (IBAction)submitButtonActionForDemo:(id)sender
{
if (![JLTValidator validateFields:#[_authRepresentative, _acceptDeclarationStatement,_homeTeamRepName,_homeTeamRepPosition,_awayTeamRepName,_awayTeamRepPosition]])
{
// how to disable a modal segue here.
return;
}
}
JLTValidator is my validating class here.
Pls suggest/help. Thanks in adv.
If you want to only allow the segue some times, you need to "name" the segue in InterfaceBuilder, then implement this routine:
- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender {
if ([identifier isEqualToString:#"your segue name"]) {
return false;
}
return true;
}
Related
I am integrating Twitter app in my iOS app. The problem is after successful login, the segue that should take the control to the specific view controller, return back to my login page and not to the desired view controller. The segue has been performed and i can see that in my output console. Also the wired thing is when i click the tweet button on login page, the segue performed second time visually at last.
My twitter login method is as follow:
- (IBAction)tweetbutton:(id)sender {
[SCTwitter initWithConsumerKey:#"your_consumer_key" consumerSecret:#"your_consumer_secret"];
[SCTwitter loginViewControler:self callback:^(BOOL success){
NSLog(#"Login is Success - %i", success);
if (success) {
[self performSegueWithIdentifier:#"authentication" sender:self];
}
}];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
NSLog(#"prepareForSegue: %#", segue.identifier);
}
The output in console is:
2014-12-10 23:54:16.923 gems[1300:60b] Login is Success - 1
2014-12-10 23:54:16.946 gems[1300:60b] prepareForSegue: authentication
I don't understand where I am wrong and why segue is not performing automatically visually on login success. Please suggest a suitable solution so that direct automatic transition to specific view controller without getting back on Login page again and also for your knowledge I am using plain view controller and not navigation controller.
Thanks in advance. Any help would be appreciated.
Using Swift 3:
Use this in viewDidLoad():
Twitter.sharedInstance().logIn { (session, error) in
if error == nil {
performSegue(withIdentifier: "authentication", sender: self)
}
}
I have a button that will segue to another View Controller. In shouldPerformSegueWithIdentifier I check the identifier and returns NO for this certain button after calling my own method nextClicked.
In nextClicked I do a HTTP Request and check some stuff, and then if everything is OK I do
dispatch_async(dispatch_get_main_queue(), ^{
[self performSegueWithIdentifier:#"getstartednext" sender:self];
});
The problem is that I get no animation now... The segue is of type modal. If I return YES in shouldPerformSegueWithIdentifier and don't to the segue programmatically later, the animation appears and everything is as it should.
You are misusing shouldPerformSegueWithIdentifier. If you want to do something special in response to the button click, use action-target and not a segue connected to the button.
I created a new project with your idea and I've got animation.
This is the action connected through IB with the next viewController and with identifier: #"getstartednext"
- (IBAction)go:(id)sender
{
}
Same code you have except sender is nil
- (void) nextClicked
{
dispatch_async(dispatch_get_main_queue(), ^{
[self performSegueWithIdentifier:#"getstartednext" sender:nil];
});
}
if sender != nil, (IBAction go:) then I'm calling nextClicked because returning NO
else the code is doing the segue because returning YES
- (BOOL) shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
{
if ([identifier isEqualToString:#"getstartednext"] && sender != nil)
{
[self nextClicked];
return NO;
}
return YES;
}
Works like a charm.
I am using a uipopover to present a mini number pad to the user when they enter a textfield on my main view controller.
when they enter numbers using the number pad, i save the entry into a nsstring property that I've named keypadvalue.
there is an unwind segue wired to a done button on the popover which fires the following code.
- (IBAction)doneWithKeyboard:(UIStoryboardSegue *)segue
{
NSLog(#"unwind");
if ([segue.sourceViewController isKindOfClass:[KeyPopupViewController class]])
{
KeyPopupViewController *popOver2 = segue.sourceViewController;
activeField.text =popOver2.keypadValue;
}
}
the activetextfield on my main view controller then gets updated to the kepadvalue, and this all works fine.
my problem now is that i want the activetextfield to update the same way if the user presses outside the uipopover, and it dismisses without firing the unwind segue.
i thought i might use the following to perform the update when the popover dismisses
-(BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
{
activeField.text = controller.keypadValue;
return YES;
}
unfortunately despite multiple attempts i can't get the property to return a value it is always null even though the method fires as expected.
how should i recover the property value from the popover using this or another method?
i am obviously doing something wrong
can anyone advise
thanks
It should help:
-(BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
{
[self.view endEditing:YES];
activeField.text = controller.keypadValue;
return YES;
}
iOS6
I have 6 UITextFields in a Scene with a Next Button that Segue's into the next Scene.
The code below works great when I hit the Done button on the keyboard:
- (IBAction)dismissKeyboard:(id)sender
{
if (sender == LocationName) {
self.meeting.LocationName = LocationName.text;
}
if (sender == LocationAddress) {
self.meeting.LocationAddress = LocationAddress.text;
}
if (sender == LocationCity) {
self.meeting.LocationCity = LocationCity.text;
}
//I have 3 more text fields after and then I persist to CoreData:
NSError *error = nil;
if (![managedObjectContext save:&error]) {
}
[sender endEditing:YES];
}
If the user hits the Done Button on the Keyboard, the data saves fine.
However, if the User hits the Next Button on the Navigation Bar, without hitting the Done button on the keyboard first, the user Typed inside the UITextfield DOES NOT SAVE. I would like for the user typed Data (Data that user inputted from the keyboard) in all the fields to be saved when the user hits the Next Button on the Navigation Bar to call the next scene.
I have the following code for the Next Button:
- (IBAction)nextButtonPressed:(id)sender {
[self dismissKeyboard:sender];
}
I know the code for nextButtonPressed is wrong. I think I need help with identifying which UITextField called the Keyboard to be visible, and then call the dismissKeyboard with passing the Sender as a parameter.
Thanks
Make use of the UITextField delegate method textFieldDidEndEditing: to know when the focus leaves a text field. This is when you should save its data. This will be called when focus moves to another text field or when the keyboard is completely dismissed.
Your implementation of nextButtonPressed: should simply call becomeFirstResponder on whatever the next text field is. That's it. By making another text field the first responder, the previous one will have its textFieldDidEndEditing: delegate called.
Update:
// This assumes the LocationXXX are instance variables referencing the UITextFields
- (IBAction)nextButtonPressed:(id)sender {
if (sender == LocationName) {
[LocationAddress becomeFirstResponder];
} else if (sender == LocationAddress) {
[LocationCity becomeFirstResponder];
// add the rest as needed
}
}
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Passing variables between view controllers
Let's say I have 3 buttons in the same ViewController(FirstController) with tags from 1-3. All three buttons opened a new ViewController(SecondController). But how can I, in the SecondController, check what button was pressed to get here, or maybe what segue was used? So the SecondController can perform different depending on which button was pressed to open it. I was maybe thinking about a switch and case.
There are 2 possible ways of doing this.
One way is to assign a unique segue to each button. On the method prepareForSegue: you identify the button and give that information to the destinationViewController:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"Button1Segue"]) {
[segue.destinationViewController setButton:1];
}
if ([segue.identifier isEqualToString:#"Button2Segue"]) {
...
}
The other way would be to create a property where you store the last pressed button.
- (IBAction)buttonTap:(id)sender {
self.lastPressedButton = sender.tag;
}
and in prepareForSegue: you would do:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"SecondControllerSegue"]) {
[segue.destinationViewController setButton: self.lastPressedButton];
}
}
Hope it helps
if (button.tag == 0) {
NSLog(#"Button one.");
} else if (button.tag == 1) {
NSLog(#"Button two.");
}
You would put something like this in the method that occurs just before the action of your three buttons. That could be viewWillDisappear, prepareForSegue, etc.
Best of luck!