this one is driving me crazy.
From my root view controller I'm pushing another view controller to force the user to enter some credentials in order to login. Unless the credentials aren't correct the user shall not be able to switch back to the root view. To accomplish this I'm trying to hide the back button but for some reason this doesn't work.
Any suggestions?
- (void)presentLoginWebView
{
UIViewController *webViewController = [[UIViewController alloc] init];
webViewController.title = NSLocalizedString(#"IB_LOG_IN_TITLE", nil);
UIWebView *webView = [[UIWebView alloc] initWithFrame:webViewController.view.frame];
webViewController.view = webView;
[self.navigationController pushViewController:webViewController animated:NO];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:IB_GET_OAUTH_TOKEN_URL]]];
webView.scalesPageToFit = YES;
webView.delegate = self; //delegate methods below
if (deviceVersion > 6)
{
[self.navigationController.interactivePopGestureRecognizer setEnabled:NO];
}
[self.navigationController.navigationItem setHidesBackButton:YES];
//The following line doesn't work either
//self.presentedViewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:[[UIView alloc] init]];
}
The following code will work. Try only navigationItem , not navigationController.navigationItem
webViewController.navigationItem.hidesBackButton = YES;
Try hiding back button of webViewController
webViewController.navigationItem.hidesBackButton = YES;
Related
I have a TableViewController, a SearchResultsController and a WebViewController. When I click on a cell in the TableViewController it pushes the WebViewController opening a url that is related to the cell.
The TableViewController has a UISearchController which filters the results into the SearchResultsController however when a cell is clicked in the SearchResultsController the WebViewController doesn't get pushed.
Here is the code for the didSelectRowAtIndexPath for the SearchResultsController:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
WebViewController *webViewController = [[WebViewController alloc] init];
NSString *extensionURL = (self.searchResults[indexPath.row])[#"url"];
NSURL *baseURL = [NSURL URLWithString:#"http://www.baseurl.com"];
NSURL *URL = [NSURL URLWithString:extensionURL relativeToURL:baseURL];
webViewController.title = (self.searchResults[indexPath.row])[#"title"];
NSLog(#"%#", URL);
webViewController.URL = URL;
[self.navigationController pushViewController:webViewController
animated:YES];
}
I included the NSLog to see if anything happened when a cell was clicked and it does display the url in the console. This makes me think the problem is with the navigationController.
Looking online it seems that the UISearchController should be wrapped in a UISearchContainerViewController which should then be put in the navigationController. I'm still new to app development and can't figure out how or where to do this.
I call my SearchResultsController in the viewDidLoad of my TableViewController like so:
- (void)viewDidLoad
{
[super viewDidLoad];
SearchResultsViewController *controller = [[SearchResultsViewController alloc] initWithStyle:UITableViewStylePlain];
[self addObserver:controller forKeyPath:#"results" options:NSKeyValueObservingOptionNew context:nil];
self.searchController = [[UISearchController alloc] initWithSearchResultsController: controller];
self.searchController.searchResultsUpdater = self;
self.searchController.hidesNavigationBarDuringPresentation = NO;
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.delegate = self;
self.definesPresentationContext = YES;
UISearchBar *searchBar = [[UISearchBar alloc] init];
searchBar = self.searchController.searchBar;
searchBar.searchBarStyle = UISearchBarStyleMinimal;
UITextField *searchField = [searchBar valueForKey:#"_searchField"];
searchBar.barTintColor = [UIColor whiteColor];
searchBar.tintColor = [UIColor whiteColor];
self.navigationItem.titleView = searchBar;
}
Is this where I should be embedding my SearchResultsController?
When doing search you will present the NewModalViewController so its simple all you need to do is some steps for pushing viewcontroller when you present search controller
1)self.definesPresentationContext = YES;
After this you should push your viewcontroller like
2) [self.presentingViewController.navigationController pushViewController:sec animated:YES];
Note:Present modalviewcontroller doesnt have Navigation controller so normal push coding wont work as it is not allocated to navigation.
Enjoy.....
You can create a property in your SearchResultsController:
#property (nonatomic, strong) UINavigationController *navController;
Then in your updateSearchResultsForSearchController in your TableViewController set the navController = self.navigationController.
Then you can do this in your SearchResultsController's didSelectRowForIndexPath:
[self.navController pushViewController:webViewController
animated:YES];
This approach worked for me after failing to get Arun's above mentioned solution to work.
I am using RESideMenu in my application. But I need to add login and registration viewcontrollers before the RESideMenu.
Is it possible, if yes then how can I do that ?
Thanks in advance.
There are many ways to do this. The most common is you have a loginView controller and then in the app delegate you can write something like this in the app delegate:
if([[NSUserDefaults standardUserDefaults] valueForKey:#"AlreadyLogin"])
{
// So, here user already login then set your root view controller, let's say `SecondViewController``
SecondViewController *secondViewController = [storyBoard instantiateViewControllerWithIdentifier:#"SecondViewController"];
// then set your root view controller
self.window.rootViewController = secondViewController;
}
else
{
// It means you need to your root view controller is your login view controller, so let's create it
LoginViewController *loginViewController= [storyBoard instantiateViewControllerWithIdentifier:#"LoginViewController"];
self.window.rootViewController = loginViewController;
}
Credit: Skip view if user already logged
Yes it is very possible.
Solution A:
After successful login/sign up, do:
[UIApplication sharedApplication].window.rootViewController = [[RESideMenu alloc] init...];
Solution B:
Place your login/signup view controllers in the main content portion of the RESideMenu, and disable the two side menus until the user is signed in.
Solution C:
Embed the RESideMenu in a UINavigationController and optionally hide the navigation bar.
For more info I recommend researching "view controller containment" as that is the pattern used by RESideMenu, UINavigationController, and other types of "container" view controllers.
I hacked together a quick example of Solution C and it seems to work fine:
#implementation LoginViewController
- (void)viewDidLoad {
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(50, 50, 100, 100);
[button setTitle:#"Login" forState:UIControlStateNormal];
[button addTarget:self action:#selector(goToRESideMenu) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
self.navigationController.navigationBarHidden = YES;
}
- (void)goToRESideMenu {
UIViewController *redViewController = [[UIViewController alloc] init];
redViewController.view.backgroundColor = [UIColor redColor];
UIViewController *greenViewController = [[UIViewController alloc] init];
greenViewController.view.backgroundColor = [UIColor greenColor];
UIViewController *blueViewController = [[UIViewController alloc] init];
blueViewController.view.backgroundColor = [UIColor blueColor];
RESideMenu *sideMenu = [[RESideMenu alloc] initWithContentViewController:redViewController
leftMenuViewController:greenViewController
rightMenuViewController:blueViewController];
[self.navigationController pushViewController:sideMenu animated:YES];
}
#end
The result looks like this:
I have buttons that opens facebook in webview on my app's mainview after i open facebook , i click to back button on navigation bar and after that i can't open facebook again. When i click the button the app doesn't crash but it doesn't do anything either.
This is my WebView's Controller
- (void)viewDidAppear:(BOOL)animated{
NSURL *socialUrl=[[NSURL alloc] initWithString:selectedUrl] ;
NSURLRequest *urlRequest=[NSURLRequest requestWithURL:socialUrl];
[webViewSocial loadRequest:urlRequest];
webViewSocial.scalesPageToFit = YES;
[self.navigationController setNavigationBarHidden:NO];
[super viewDidAppear:animated];}
And this is my code in mainview:
- (IBAction)facebookTouched:(id)sender {
socialPage = [[SocialMediaViewController alloc] initWithNibName:#"SocialMediaViewController" bundle:[NSBundle mainBundle]] ;
socialPage.selectedUrl = URL_FACEBOOK ;
socialPage.title = #"Facebook";
[self.navigationController pushViewController:socialPage animated:YES]; }
OK I solved my problem.
I deleted this part from my MainViewController and it worked.I did not think that this part was important so i didn't write it to my question.
(void)viewWillAppear:(BOOL)animated{
NSMutableArray *navigationArray = [[NSMutableArray alloc] initWithArray: self.navigationController.viewControllers];
[navigationArray removeObjectAtIndex: 0];
self.navigationController.viewControllers = navigationArray;
[self.view setNeedsDisplay];
[super viewWillAppear:animated];
}
I am using a popover view to present a large amount of flags of which the your can select.
There is something wrong with my code since soon after I open this popover memory is not released (the viewcontroller "flagsViewController" is ok and clean, it does init and release each and every item inside of it.
What am I doing wrong? How can I free memory as soon as the popover is closed?
-(void)presentFlags
{
[self.popoverController dismissPopoverAnimated:YES];
FlagsViewController *controller = [[FlagsViewController alloc]
initWithNibName:#"FlagsViewController"
bundle:[NSBundle mainBundle]] ;
UINavigationController *container = [[UINavigationController alloc] initWithRootViewController:controller];
UISegmentedControl *ctrl = [[UISegmentedControl alloc] initWithItems:segmentedItems];
ctrl.frame = CGRectMake(0, 6, 500, 30);
[ctrl addTarget:self action:#selector(changeSeg:) forControlEvents:UIControlEventValueChanged];
ctrl.segmentedControlStyle = UISegmentedControlStyleBar;
//ctrl.momentary = YES;
ctrl.tintColor = [UIColor darkGrayColor];
UIImage *theImage = [UIImage imageNamed:#"highlight_country.png"];
[ctrl setImage:theImage forSegmentAtIndex:0];
[container.navigationBar addSubview:ctrl];
[ctrl release];
//
//create a popover controller
self.popoverController = [[[UIPopoverController alloc]
initWithContentViewController:container] autorelease];
[container release];
[popoverController setPopoverContentSize:CGSizeMake(500, 600)];
//present the popover view non-modal with a
//refrence to the button pressed within the current view
[popoverController presentPopoverFromRect:CGRectMake(popoverArrowPossition, 0.0, 0.0, 52.0) inView:super.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
[controller release];
}
Working with the UIPopoverController has been pretty difficult but I solved this problem by doing the following setting the Delegate of the Popover Controller to self (popoverController.delegate = self) and adding the UIPopoverControllerDelegate Protocol to your Class Header
Next, I implemented the - (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController delegate method and here I released the popoverController and set it to nil.
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
[self.popoverController release];
self.popoverController = nil;
}
Please note: This delegate method won't be called if you dismiss the popover via code (i.e. using dismissPopoverAnimated), it'll only be called if this User dismisses it by tapping outside the popover etc.
I have encountered a strange behaviour when presenting my modal view. I have a scroll view on as my main view with 4 pages... tapping on a button on the scroll view presents the modal view, but i can dismiss the modal view by swiping left or right. Obviously i just want to be able to dismiss using the Done button.
This is the method i use to display the modal view:
- (void)popUpModal:(id)sender {
UIViewController *detailView = [[UIViewController alloc] initWithNibName:#"KeyboardView" bundle:nil];
detailView.view.backgroundColor = [UIColor blackColor];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:detailView];
UIBarButtonItem * doneButton =
[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self action:#selector(doneAction) ];
detailView.navigationItem.rightBarButtonItem = doneButton;
[doneButton release];
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
NSString *url = #"http://www.google.com";
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
[detailView.view addSubview:webView];
[self presentModalViewController:navController animated:YES];
[detailView release];
[navController release];
}
What would cause this behaviour?
Thanks.