I have 3 classes.
First controllor is the first controllor in tabbar. I am using presentModalViewController to present a login screen and a Home screen. I have a presentModalViewController in firstcontrollor which present the login screen and in Loginscreen viewdidload method I have presentModalViewController which present home screen. The home screen presentModalViewController is dismissed in homePage_Btn_Clicked and presentModalViewController is dismissed in login_Btn_Clicked. The problem I have is my home screen is never presented. Any help? I am new in iPhone development.
//First Controllor
FirstControllor.m
- (void)viewDidLoad
{
[super viewDidLoad];
Accounts_Login *lvc = [[Accounts_Login alloc]initWithNibName:#"Accounts_Login" bundle:[NSBundle mainBundle]];
[self presentModalViewController:lvc animated:NO];
[lvc release];
}
//Login_view class
Login_view.m
- (void)viewDidLoad {
[super viewDidLoad];
Home_Screen *lvc1 = [[Home_Screen alloc]initWithNibName:#"Home_Screen" bundle:[NSBundle mainBundle]];
[self presentModalViewController:lvc1 animated:NO];
[lvc1 release];
user_ID_TextField.text = [[NSUserDefaults standardUserDefaults] objectForKey:#"User ID"];
}
-(IBAction) login_Btn_Clicked{
if ([services authenticate:credential_Data]) {
[self dismissModalViewControllerAnimated:YES];
[credential_Data autorelease];
}
//HomePage class
HomePage.m
-(IBAction) homePage_Btn_Clicked:(id) sender{
UIButton *theButton = (UIButton *)sender;
int count;
switch (theButton.tag) {
case 101:
count++;
[self dismissModalViewControllerAnimated:YES];
break;
default:
break;
}
}
Move presentModalView from viewDidLoad to viewDidAppear.
Try this:
Home_Screen *lvc1 = [[Home_Screen alloc]initWithNibName:#"Home_Screen" bundle:[NSBundle mainBundle]];
[self.parentViewController presentModalViewController:lvc1 animated:NO];
[lvc1 release];
Related
I have a view(HomeView) in which i open a popOver. The popoVer content View is (ListView) which contains a Table View.
Now, when i select the row, The HomeView will dismissed & open a new View(MapView).
Till now, It works fine. But my all views contain tabbar in xib. I don't have tab bar in ListView.
So, i just open MapView with present Modal View. But from that my navigation is not working.
My code is as following.
HomeView.m
//open popview with ListView
-(IBAction)btnTableMenu_TouchUpInside:(id)sender{
ListView *popUp=[[ListView alloc] initWithNibName:#"ListView" bundle:nil];
popView = [[UIPopoverController alloc]initWithContentViewController:popUp];
popView.delegate =self;
[popView setPopoverContentSize:CGSizeMake(300, 700)];
[popView presentPopoverFromRect:CGRectMake(150,25,20,50) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
ListView.m
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[[NSNotificationCenter defaultCenter] postNotificationName:#"DismissModal"object:self];
MapViewController *mapVC=[[MapViewController alloc]initWithNibName:#"MapViewController_ipad" bundle:nil];
[self presentModalViewController:mapVC animated:YES];
//[self.navigationController pushViewController:mapVC animated:YES];
}
How can i solve this??
you just do like this way:-
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[[NSNotificationCenter defaultCenter] postNotificationName:#"DismissModal"object:self];
MapViewController *mapVC=[[MapViewController alloc]initWithNibName:#"MapViewController_ipad" bundle:nil];
UINavigationController *navbar = [[UINavigationController alloc] initWithRootViewController:mapVC];
navbar.navigationBar.tintColor =[UIColor colorWithRed:255/255.0 green:108/255.0 blue:61/255.0 alpha:0.1];
[navbar setModalPresentationStyle:UIModalPresentationFormSheet];
[navbar setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:navbar animated:YES];
}
in MapViewController.m file ViewDidLoad
- (void)viewDidLoad
{
[super viewDidLoad];
UIBarButtonItem *CancleButton = [[UIBarButtonItem alloc] initWithTitle:#"Cancel" style:UIBarButtonItemStyleBordered target:self action:#selector(cancel)];
self.navigationItem.leftBarButtonItem = CancleButton;
}
-(void)cancel
{
[self dismissModalViewControllerAnimated:YES];
}
Do you know the difference btw ..
[self presentModalViewController:controller animated:YES];
& [self.navigationController pushViewController:controller animated:YES];
\When you do presentModalViewController:controller you lost the last Navigation stack.You need to create different navigationController for presenting the View. Read this properly you will get Idea .
http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/Introduction/Introduction.html
Try following these-
ListView.m
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[[NSNotificationCenter defaultCenter] postNotificationName:#"DismissModal"object:self userInfo:[NSDictionary dictionaryWithObject:#"map" forKey:#"selectedView"]];
}
HomeView.m
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(dismissModal:) name:#"DismissModal" object:nil];
- (void) dismissModal:(NSNotification *)notification
{
[self dismissModalViewController:mapVC animated:NO];
if([[notification.userInfo valueForKey:#"selectedView"] isEqualToString:#"map"])
{
MapViewController *mapVC=[[MapViewController alloc]initWithNibName:#"MapViewController_ipad" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:mapVC];
[self presentModalViewController:navController animated:YES];
}
}
I am having a popovercontroller to dispay a search page ,it shows the search page nicly,when the user tap the cell inside the popover it will show the corresponding page inside the popovercontroller,I dont want it,so I put the NSNotification for displaying the popover,and it works fine,but I got a problem that ,but navigation is not happen there in popovercontroller ,only dismissal happen.
this is my code to create a popover
-(void)revealRightSidebar:(id)sender
{
searchpage* popoverContent = [[searchpage alloc]
init];
UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController:popoverContent] autorelease];
//resize the popover view shown
//in the current view to the view's size
popoverContent.contentSizeForViewInPopover =
CGSizeMake(320,650);
//create a popover controller
self.popup = [[UIPopoverController alloc]
initWithContentViewController:navigationController];
[self.popup presentPopoverFromRect:_btnsearch.frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
//release the popover content
[popoverContent release];
[self resetReadViewToVerse:1];
}
in viewDidLoad method of this page i put the notification
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(dismissThePopover) name:#"popoverShouldDismiss" object:nil];
}
in searchpage i put this code to navigate to the corresponding search result page
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ParallelReadViewController *detailViewController = [[ParallelReadViewController alloc] initWithNibName:#"ParallelReadViewController" bundle:nil];
//detailViewController.firstString = firstString;
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
delegate.selectedBook = [[searchResults objectAtIndex:indexPath.row] objectForKey:#"book"];
delegate.selectedChapter = [[searchResults objectAtIndex:indexPath.row] objectForKey:#"chapter"];
delegate.selectedVerse = [[searchResults objectAtIndex:indexPath.row] objectForKey:#"verse"];
[delegate reloadVerses];
[[NSNotificationCenter defaultCenter] postNotificationName:#"popoverShouldDismiss" object:nil];
}
but when I remove the notification it navigate to the correspondent search in parallelReadViewController page ,but within the popover itself,here the popover dismiss,but no navigation.please help me to do this.
You must be having a navigationController declared inside the AppDelegate class. Use that navigationController for pushing the required view.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ParallelReadViewController *detailViewController = [[ParallelReadViewController alloc] initWithNibName:#"ParallelReadViewController" bundle:nil];
//detailViewController.firstString = firstString;
// ...
// Pass the selected object to the new view controller.
[delegate.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
delegate.selectedBook = [[searchResults objectAtIndex:indexPath.row] objectForKey:#"book"];
delegate.selectedChapter = [[searchResults objectAtIndex:indexPath.row] objectForKey:#"chapter"];
delegate.selectedVerse = [[searchResults objectAtIndex:indexPath.row] objectForKey:#"verse"];
[delegate reloadVerses];
[[NSNotificationCenter defaultCenter] postNotificationName:#"popoverShouldDismiss" object:nil];
}
Hope this might help you.......
I am currently added a new view when a mapkit annotation is clicked:
-(IBAction)showDetails:(id)sender{
DetailViewController *dvc = [[DetailViewController alloc] init];
dvc.title = ((UIButton*)sender).currentTitle;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:dvc];
[self presentModalViewController:navigationController animated:YES];
}
What I would like to do is on the new view is have a back button that will remove the view and display the mapkit again.
I am using a tabbar in the normal app. I have setup a button on the new view and tried this:
- (IBAction)backToMap:(id)sender {
UINavigationController *nc = [self navigationController];
NSLog(#"%#", [nc viewControllers]);
[nc popViewControllerAnimated:NO];
NSLog(#"%#", [nc viewControllers]);
[nc popToRootViewControllerAnimated:NO];
NSLog(#"Close");
}
But it doesn't make any visual difference.
Help Appreciated.
You need to dismiss this modal viewController:
- (IBAction)backToMap:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}
Hay Mark you can try with
[self.parentViewController dismissModalViewControllerAnimated:YES];
I am presenting a modalcontroller in a view, after i dissmiss the view i want to present another modalView but the code is not working, i have a delegate method that is being called when i press a button on the first modal vieview in witch i have the code.
inside the parentView the method for the firstview delegat:
-(void)newMessageModalView:(NewMessageModalView *)controller didFinishSelecting:(int)selectedChannel{
[self dismissModalViewControllerAnimated:YES];
SecondView * detailView = [[SecondView alloc] initWithNibName:#"SecondView" bundle:nil];
[self presentModalViewController:SecondView animated:YES];
[detailView release];
[self dismissModalViewControllerAnimated:YES];
}
You are presenting SecondView, which is your class and not your instance. Even if that was right, you are dismissing it straight away.
Move [self dismissModalViewControllerAnimated:YES]; to detailView.m
-(void)newMessageModalView:(NewMessageModalView *)controller didFinishSelecting:(int)selectedChannel{
SecondView * detailView = [[SecondView alloc] initWithNibName:#"SecondView" bundle:nil];
[self presentModalViewController:SecondView animated:YES];
[detailView release];
}
For example, in detailView.m
- (void)cancelBtnTouched:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}
I have the following action that gets called when a button gets clicked. The log message gets printed yet, the view doesn't change. This function is in a UIViewController.
Any ideas what I am doing wrong? Why isn't the new view being displayed with a red background?
- (void)viewDidLoad
{
[levelButton2 addTarget:self action:#selector(clickButton) forControlEvents:UIControlEventTouchUpInside];
//MORE CODE
}
- (void) clickButton
{
NSLog(#"Clicked Button");
UIViewController *myViewController = [[UIViewController alloc] init];
myViewController.title = #"My First View";
myViewController.view.backgroundColor = [UIColor redColor];
//to push the UIView.
[self.navigationController pushViewController:myViewController animated:YES];
//[self.navigationController pushViewController:nextController animated:YES];
}
-(void) clickButton
{
NSLog(#"Clicked Button");
MyFirstController *myViewController = [[MyFirstController alloc] init];
[self.navigationController pushViewController:myViewController animated:YES];
[myViewController release];
}
Then after go into the MyFirstController.m file and
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
if(self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])
{
self.title = #"My First View";
}
return self;
}
I hope it will help you.
You havent used or mention NIB file in that controller..Add NIB file or else make set root view controller of a navigation with a view controller and push the view controller
You have to change your IBAction method a little bit as,
- (void) clickButton
{
NSLog(#"Clicked Button");
MyFirstController *myViewController = [[MyFirstController alloc] initWithNibName:#"MyFirstController" bundle:nil];
myViewController.title = #"My First View";
myViewController.view.backgroundColor = [UIColor redColor];
//to push the UIView.
[self.navigationController pushViewController:myViewController animated:YES];
//[self.navigationController pushViewController:nextController animated:YES];
}