I have a home view ,when click on that it is going to another view again i am going to another view.when click on a button on that view a modalview will appear and then subsequently 3 more modal views when click on each modalview.when click on the final modalview an alert will appear and when click on that alert i want to show the root homeview.Is it possible ?
Asked
Active
Viewed 373 times
4 Answers
1
Display AlertView using given code snippet:
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:title message: @"Alert Message" delegate: self cancelButtonTitle:@"Ok" otherButtonTitles: nil]; [alert show]; [alert release];
Delegate Method implementation :
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { [self.navigationController popToRootViewControllerAnimated:YES];
}

Meenakshi
- 1,162
- 9
- 13
0
Sample Code given below:
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Alert Message?" message:@"Error......" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK"] autorelease];
[alert show];
The implemention alertView's delegate functions is given below
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
//cancel clicked ...do your action
}
else if (buttonIndex == 1)
{
//OK clicked
[self.navigationController popToViewController animated:YES];
}
}

Paresh Navadiya
- 38,095
- 11
- 81
- 132
-
I did like this but it is still staying on the current view itself not going to rootview. – priyanka vijesh Aug 27 '12 at 12:13
0
int c=[self.navigationController.viewControllers count]-4;
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:c] animated:YES];

Mihai Iorga
- 39,330
- 16
- 106
- 107

Akram Khan
- 61
- 3
0
just give the delegate in .h file and after in delegate method of alertview write bellow code..
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 1) {
[self.navigationController popToRootViewControllerAnimated:YES];///this line is important..
}
else{
// do your action...
}
}
i hope this answer is useful to you..
:)

Paras Joshi
- 20,427
- 11
- 57
- 70
-
you push every view from homeviewcontroller?? and also first try this code on simple UIButton click event just try... – Paras Joshi Aug 27 '12 at 12:24
-
put [self.navigationController popToRootViewControllerAnimated:YES]; this line in also else part in above method ... or change the condition from buttonindex == 1 to buttonindex == 0. – Paras Joshi Aug 27 '12 at 12:26