UIAlertView button to another ViewController - iphone

I have two buttons for my UIAlertView. One of them goes back to TableViewController while another one have to go to another ViewController. The button that goes to the TableViewController can work. But the button that goes to the ViewController is showing me a blank view when I click the button.
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
QuizTableViewController *quizTable = [self.storyboard instantiateViewControllerWithIdentifier:#"quizTable"];
UINavigationController *quizController = [[UINavigationController alloc] initWithRootViewController:quizTable];
[quizController setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentViewController:quizController animated:YES completion:nil];
}
if (buttonIndex == 1)
{
QuizAnsViewController *quizAns = [[QuizAnsViewController alloc] initWithNibName:nil bundle:nil];
[self presentViewController:quizAns animated:YES completion:nil];
}
}
The second part of the code is for the button to go another ViewController.
Anybody can help please? Thank you.

It seems you are using Story board so this might work
if (buttonIndex == 1){
QuizAnsViewController *quizAns = [self.storyboard instantiateViewControllerWithIdentifier:#"Identifier_of_that_view_controller"];
[self presentViewController:quizAns animated:YES completion:nil];
}

you use NavigationController than I think this code is Solve your problem. You can Try.
if (buttonIndex == 1)
{
QuizAnsViewController * quizAns = [[[QuizAnsViewController alloc] initWithNibName:#"QuizAnsViewController" bundle:nil] autorelease];
[self.navigationController quizAns animated:YES];
}

Related

How to navigate the view in iphone programming?

In my appController's ViewDidLoad, I have done some thing as below
- (void)viewDidLoad
{
self.overlayViewController =
[[[OverlayViewController alloc] initWithNibName:#"OverlayViewController" bundle:nil] autorelease];
// as a delegate we will be notified when pictures are taken and when to dismiss the image picker
self.overlayViewController.delegate = self;
self.capturedImages = [NSMutableArray array];
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
// camera is not on this device, don't show the camera button
NSMutableArray *toolbarItems = [NSMutableArray arrayWithCapacity:self.myToolbar.items.count];
[toolbarItems addObjectsFromArray:self.myToolbar.items];
[toolbarItems removeObjectAtIndex:2];
[self.myToolbar setItems:toolbarItems animated:NO];
}
}
I have two methods as below,
- (IBAction)cameraAction:(id)sender
{
[self showImagePicker:UIImagePickerControllerSourceTypeCamera];
}
- (void)showImagePicker:(UIImagePickerControllerSourceType)sourceType
{
if (self.imageView.isAnimating)
self.imageView.stopAnimating;
if (self.capturedImages.count > 0)
[self.capturedImages removeAllObjects];
if ([UIImagePickerController isSourceTypeAvailable:sourceType])
{
[self.overlayViewController setupImagePicker:sourceType];
[self presentModalViewController:self.overlayViewController.imagePickerController animated:YES];
}
}
Now as I click the button, the method will launch the class showing custom view, I want to call this without clicking the button, what should I do ?
I wrote the button coding directly in ViewDidLoad, but not working at all
This code, I took from apple's documentation as example
Help !
If I understand correctly, you are wanting to show a view?
If so you could push using:
[self.navigationcontroller pushviewcontroller:YOURVIEWCONTROLLER animated:YES];
Or you could present it using:
[self presentModalViewControllerpushviewcontroller:YOURVIEWCONTROLLER animated:YES];

Adding IBAction to a UIAlert

I was trying to get my UIAlert to do two different actions when the buttons are clicked. When the user clicks restart, the game restarts and when main menu is clicked, the game should go to the main menu. The reset button is working fine but the IBAction keeps giving me errors about switching views.
// called when the player touches the "Reset Game" button
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
// the user clicked one of the OK/Cancel buttons
if (buttonIndex == 0)
{
[self resetGame];
}
else
{
- (IBAction)showFlip:(id)sender {
Menu *menuView = [[[menu alloc] init] autorelease];
[gameView setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:menuView animated:YES];
}
}
}
The reset works fine but I am getting two errors on the IBAction. 'showFlip' undeclared (first use in this function) and expected ';' before ':' token. Don't understand why it would say this because when I post the IBAction outside of the alertview it works fine.
Any help would be appreciated, thanks in advance
You are defining a method, not calling one! This code
- (IBAction)showFlip:(id)sender {
Menu *menuView = [[[menu alloc] init] autorelease];
[gameView setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:menuView animated:YES];
}
should not live inside this function. Pull it out to be
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
// the user clicked one of the OK/Cancel buttons
if (buttonIndex == 0)
{
[self resetGame];
}
else
{
[self showFlip];
}
}
-(void)showFlip{
Menu *menuView = [[[menu alloc] init] autorelease];
[gameView setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:menuView animated:YES];
}
You should try this:
// called when the player touches the "Reset Game" button
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
// the user clicked one of the OK/Cancel buttons
if (buttonIndex == 0)
{
[self resetGame];
}
else
{
[self showFlip:nil];
}
}
- (IBAction)showFlip:(id)sender {
Menu *menuView = [[[menu alloc] init] autorelease];
[gameView setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:menuView animated:YES];
}

Cancel and done button does not work in new contact view

I am trying to integrate new contact control in my app. Here is my code:
- (BOOL) personViewController:(ABPersonViewController*)personView shouldPerformDefaultActionForPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifierForValue
{
return YES;
}
-(IBAction)addcontact:(id)sender{
ABNewPersonViewController *picker = [[ABNewPersonViewController alloc] init];
UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:picker];
[self presentModalViewController:navigation animated:YES];
[picker release];
[navigation release];
}
It pops up new contact view but when I click Cancel or Done button nothing happens.
Can anyone help me?
Thanks in advance!
//Make sure your VC is an <ABNewPersonViewControllerDelegate>
-(void) newPersonViewController:(ABNewPersonViewController *)newPersonView
didCompleteWithNewPerson:(ABRecordRef)person {
if (person != nil) //nil = Cancel button clicked
{
//do something
}
//iOS6
[self dismissViewControllerAnimated:YES completion:nil];
}
You need to add methods that should be called when the cancel or done button is tapped and that method should call [self.navigationController dismissModalViewController

How to make Action Sheet button open new view

I have an iPhone app that uses an action sheet but I can't work out how to make one of the buttons open a new view when pressed. I know how to implement the action sheet - that's not a problem, its the actual action of opening the new view that's the issue.
Any help would be greatly appreciated. Thanks.
I usually just create a new method and have the action sheet do it.
For instance:
switch (buttonIndex) {
case 0:
[self openModalView];
break;
}
Then, in your openModalView method:
- (void)openModalView {
MyModalViewController *myController = [[MyModalViewController alloc] init];
[self presentModalViewController:myController animated:YES];
[myController release];
}
In the UIAlertView's -didDismissWithButtonIndex, instantiate your new view controller and push it onto the navigation stack:
- (void)alertView:(UIAlertView *)alertView
didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
NewViewController *controller = [[NewViewController alloc] init];
[[self navigationController] pushViewController:controller animated:YES];
[controller release], controller = nil;
}
}

Alertview click to UITableviewcontroller

am new to iphone programming. I have a viewcontoller with an alertview in it. When the ok button on alertview is clicked it takes to another UITableviewcontroller. I am able to get my cells with objects in it. but am unable to get the navigation bar on top. please tell me y is it so?
thanks
viki
-(void)alertView:(UIAlertView *) alertview clickedButtonAtIndex:(NSInteger)buttonIndex {
if(buttonIndex == 1){
Accidenthelpercall* help = [[Accidenthelpercall alloc]initWithNibName:#"Accidenthelpercall" bundle:nil];
[self presentModalViewController:help animated:YES];
[help setTitle:#"Accident Helper"];
[help release];
}
if(buttonIndex == 2)
{
Accidentdamagecar* damagecar = [[Accidentdamagecar alloc]initWithNibName:#"Accidentdamagecar" bundle:nil];
[[self navigationController] pushViewController:damagecar animated:YES];
[damagecar setTitle: #"Car Damage"];
[damagecar release];
}
}