Alertview click to UITableviewcontroller - uialertview

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];
}
}

Related

UIAlertView button to another ViewController

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];
}

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];
}

New UIView not loading

I have a TabController View setup and I am attempting to load a new view in the current tab. This view would be loaded depending on a selection from a UIAlertView.
As such I have this code attempting to do so:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{
// Yes Button
if (buttonIndex == 0) {
NSLog(#"%# Pressed", [alertView buttonTitleAtIndex:0]);
user = [[UserInfo alloc] initWithNibName:#"UserInfo" bundle:nil];
[self.navigationController pushViewController:user animated:YES];
[user release];
}
// Don't show again Button
if (buttonIndex == 1) {
NSLog(#"%# Pressed", [alertView buttonTitleAtIndex:1]);
}
// No Button
if (buttonIndex == 2) {
NSLog(#"%# Pressed", [alertView buttonTitleAtIndex:2]);
}
}
The Yes block prints out to the console, however the new view does not load. User is an instance of UserInfo, which in turn is a subclass of UIViewController. The Nib UserInfo is created and is part of the project.
What am I missing?
These two lines are unnecessary:
[user.view setHidden:NO];
[self.navigationController setView:user.view];
But this one is:
[user release];
How are you setting up your tab bar controller? Have you placed this view inside of a UINavigationController then added that navigation controller to the TabBarController?
Please review the View Controller Programming Guide for iOS (specifically the Combined ViewController Interfaces section) and verify you are nesting these views correctly.
Is user a global variable? I usually see something like
UserInfo *user = [[UserInfo alloc] initWithNibName:#"UserInfo" bundle:nil];
as the pattern. Since the navigation controller is really going to be the main owner of the view

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;
}
}