iOS change scene with code - ios

I need to change to another scene after clicking an alert view button.
Here is my code:
(IBAction)confirmar {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Confirmar"
message:#"Confirma que desea recibir notificaciones en su teléfono móvil"
delegate:self
cancelButtonTitle:#"Cancelar"
otherButtonTitles:#"Si quiero participar", nil];
[alertView show];
}
(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:
(NSInteger)buttonIndex {
if (buttonIndex == 1) {
inscrito *cambia = [[inscrito alloc] initWithNibName:#"inscrito" bundle:nil];
[cambia setTitle:#"inscrito"];
cambia.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
// [self.navigationController pushViewController:cambia animated:YES];
[self.navigationController presentModalViewController:cambia animated:YES];
[cambia release];
NSLog(#"Boton 1");
}
}
I'm trying to change to the UIViewController called "inscrito".
I also added: #import "inscrito.h" at top of the file...

I usually use UIViewController, but it appears you might want to push the new viewcontroller
http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html
Pushing and Popping Stack Items
– pushViewController:animated:
– popViewControllerAnimated:
– popToRootViewControllerAnimated:
– popToViewController:animated:

I think the first code is right, but you need to change this :
[self.navigationController presentModalViewController:cambia animated:YES];
with this :
[self presentModalViewController:cambia animated:YES];
If you don't have navigationController, it won't work.Hope it help

Related

UIAlertView delayed or not showing up when calling methods from another view

UIAlertView delayed or not showing up when pass another view. Any help would be greatly appreciated.
-(void)viewDidLoad{
levelContentController = [[UIAlertView alloc] initWithTitle:#""
message:#"Loading...
delegate:self
cancelButtonTitle:nil
otherButtonTitles:nil];
}
-(void)passToTestView:(id)sender{
[levelContentController show];
ViewController *viewController = [[ViewController alloc]init];
clickedLevelId = [[NSString alloc] init];
clickedLevelId = [testIdStringArray objectAtIndex:[sender tag]-1];
[viewController sendIndexMethod:sendIndex];
[viewController testCompletedArrayMethod:arrayOfCompletedTest];
[viewController parseTestURL:buttonTag getTestIdString:clickedLevelId];
viewController.viewSoundCheck = _levelSoundCheck;
[self presentViewController:viewController animated:YES completion:nil];
}
-(void)viewWillDisappear:(BOOL)animated{
[levelContentController dismissWithClickedButtonIndex:0 animated:YES];
}
The above code has some problems.
When passToTestView: selector is called, it'll try to present the alertView. But within the same method you are trying to present another view controller.
This will in turn call viewWillDisappear: where you are hiding the alertView.
It's recommended that if you want to present the alertView while displaying ViewController, create and display UIAlertView instance in the ViewController class's viewDidLoad or viewWillAppear:. Do not initialise and display it in this viewController.
To make the UIAlertView appear, you should call:
[contentLoadingController show];
Note that UIAlertView is deprecated in iOS9, and you should use UIAlertController.

How to connect a UI alert button to another view Controller?

I have already created UI alert and call a function.
UIAlertView *alertView1 = [[UIAlertView
alloc]initWithTitle:#"Test"message:#"Working 1!!"delegate: self
cancelButtonTitle:#"OK"otherButtonTitles:nil];
[alertView1 show];
Method for call newView viewController
- (void)alertView:(UIAlertView *)alertView
didDismissWithButtonIndex:(NSInteger) buttonIndex
{
if (buttonIndex == 0)
{
NSLog(#"Cancel Tapped.");
}
else if (buttonIndex == 1)
{
// NSLog(#"OK Tapped. Hello World!");
UIViewController *newView = [[UIViewController alloc] init];
[self presentViewController:newView animated:YES completion:nil];
}
}
I have created a new class named "newView" and also add "UIAlertViewDelegate" in present view controller.
But my problem is, I couldn't connect the newView viewcontroller with my present view controller.
Here you are creating object in memory so that's why you can now only access properties and public methods of newView. Can not make presentation of newView.
You can achieve this by 2 ways.
Either you can make this possible by calling Segue or you have to create newView object from Storyboard.
ViewController *entryController = [self.storyboard instantiateViewControllerWithIdentifier:#"go"];
[self.navigationController pushViewController:entryController animated:YES];

iOS redirect back to apps

I need help , googling also put me at no clue thus i'll post here for guidance and assist.
My situation is that I want the app delegate.m after when you press Ok, I want a simple redirect back to another view . Is that possible?
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Daily Vibes"
message:notification.alertBody
delegate:self cancelButtonTitle:#"Okay"
otherButtonTitles:nil];
[alert show];
}
Is it possible to do ?? After they click the cancel button Okay then they'll just be redirect back to the apps a specific page???
Try this:
Make your app delegate conforms to the UIAlertViewDelegate protocol, and add this code:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:#"Okay"])
{
NSLog(#"Okay was selected.");
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
MyViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"MyViewController"];
[(UINavigationController*)self.window.rootViewController pushViewController:vc animated:NO];
}
else if([title isEqualToString:#"Hello"])
{
NSLog(#"Hello was selected.");
}
}
The delegate captures the selected button, checks the title, and acts accordingly. In this case, since you are in the app delegate, you have to do a manual push of the view controller (you aren't in a view controller, so theres no pushing allowed)

tabBarController delegate didn't work

I use below delegate method to set the tabBarController not to pop to another sub view controller by setting the return value to NO,
-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
UIViewController *vc =[((UINavigationController *)viewController).viewControllers objectAtIndex:0];
if ([vc isKindOfClass:NSClassFromString(#"LYAppCategoryViewController")]) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"" message:#"" delegate:self cancelButtonTitle:#"" otherButtonTitles:#"", nil];
[alert show];
return NO;
}
else {
return YES;
}
}
but after "NO" was actually returned,the tabBarController still pop to another sub view controller. So it's kinda puzzling,am I getting it wrong, the scenario of using it?
quotes from Apple API "YES if the view controller’s tab should be selected or NO if the current tab should remain active."
thanks a lot for your kind help.
I still didn't get the reason why this happened,but I accomplished my target by adding codes like this:
[tabBarController setSelectedViewController:[[tabBarController viewControllers] objectAtIndex:0]];
[tabBarController setSelectedIndex:0];
tabBarController will not pop to another view controller if "forcing" to pop to the first one.

iOS Dev: Segue by pressing a button in an Alert?

I've been searching for a few hours and haven't found any answers, so I would really appreciate your help!
I am designing an app and need to segue to a different view controller when a button in an alert is pressed. I already have the alert set up, but just need the code to segue to a new view.
Try this. create alertview first.
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:#"Message" message:#"Open New controller?" delegate:self cancelButtonTitle:#"No" otherButtonTitles:#"Yes",nil];
[alertView show];
[alertView release];
Implement the AlertView Delegate Method
#pragma mark AlertView Delegate
-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex != alertView.cancelButtonIndex)
{
Viewcontroller *vc = [[UIViewcontroller alloc] initWithNib:#"Viewcontroller"];
[self presentModalViewController:vc];
[vc release];
}
}
Implement the UIAlertViewDelegate and add the method alertView:clickedButtonAtIndex:. Once the right button is clicked, call the method to segue into the new view.
Implement UIAlertViewDelegate and then you get a callback with which button was pressed when the alert was dismissed. Simply call performSegueWithIdentifier in there.
More details at the UIAlertViewDelegate protocol reference

Resources