While I am navigating to the particular controller I want keyboard to enable after the navigation takes place. In IndexPageTableViewController it has a textField named searchField I need to enable the keyboard.
-(void) navigateToSearch
{
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main_iPhone"
bundle: nil];
if(mainStoryboard)
{
IndexPageTableViewController *index = (IndexPageTableViewController *) [mainStoryboard instantiateViewControllerWithIdentifier:#"IndexPageTableViewController"];
[[SlideNavigationController sharedInstance ] popToRootAndSwitchToViewController:index withSlideOutAnimation:NO andCompletion:^{
[self initTableView];
[self becomeFirstResponder];
}];
}
}
Related
I am using CAPSPageMenu for page controller, loading two view controllers as a first screen, but it is not displaying controller title array in 6s plus device. it is displaying like this,
I want to display half the screen as for screen size.
Here is my code i am using ,
NSArray *controllerArray = #[jobVC, course];
NSDictionary *parameters = #{CAPSPageMenuOptionMenuItemSeparatorWidth: #(1.0),
CAPSPageMenuOptionUseMenuLikeSegmentedControl: #(YES),
CAPSPageMenuOptionMenuMargin:#(20.0),
CAPSPageMenuOptionMenuItemSeparatorRoundEdges: #(YES),
CAPSPageMenuOptionSelectionIndicatorHeight :#(2.0),CAPSPageMenuOptionMenuItemSeparatorPercentageHeight: #(0.5)
};
_pageMenu = [[CAPSPageMenu alloc] initWithViewControllers:controllerArray frame:CGRectMake(0.0, 0.0, self.contentView.frame.size.width, self.contentView.frame.size.height) options:parameters];
_pageMenu.delegate = self;
[self.contentView addSubview:_pageMenu.view];
You should set your view contollers correctly. Like this way:
Firstly add a property for CAPSPageMenu in your base view controller:
#property (nonatomic) CAPSPageMenu *pagemenu;
Then add following code in the viewDidLoad function in your view controller:
NSMutableArray *controllerArray = [NSMutableArray array];
// Example view controller creation:
UIViewController *firstController = [UIViewController alloc] initWithNibname:#"YourFirstControllerNibName" bundle:nil];
controller.title = #"YOUR SAMPLE TITLE (eg. SEARCH JOBS)";
[controllerArray addObject:firstControllerName ];
UIViewController *secondController = [UIViewController alloc] initWithNibname:#"YourSecondControllerNibName" bundle:nil];
secondController .title = #"YOUR SAMPLE TITLE (eg. SEARCH COURSE)";
[controllerArray addObject:secondController ];
//Customize your page menu with parameters:
NSDictionary *parameters = #{CAPSPageMenuOptionMenuItemSeparatorWidth: #(1.0),
CAPSPageMenuOptionUseMenuLikeSegmentedControl: #(YES),
//... and more...
};
// Initialize page menu
_pageMenu = [[CAPSPageMenu alloc] initWithViewControllers:controllerArray frame:CGRectMake(0.0, 0.0, self.view.frame.size.width, self.view.frame.size.height) options:parameters];
//Optional delegate
_pageMenu.delegate = self;
// Lastly add page menu as subview of base view controller view
[self.view addSubview:_pageMenu.view];
You can also use these delegate functions below for control move actions if you want:
- (void)willMoveToPage:(UIViewController *)controller index:(NSInteger)index {}
- (void)didMoveToPage:(UIViewController *)controller index:(NSInteger)index {}
I've subclass UINavigationController like this:
#implementation BaseNavigationController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1];
}
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
if (self.viewControllers.count) {
viewController.hidesBottomBarWhenPushed = YES;
}
[super pushViewController:viewController animated:animated];
}
And also I've a subclass of UIViewController like this:
#implementation BaseViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.tabBarController.tabBar.translucent = NO;
self.navigationController.navigationBar.translucent = NO;
self.view.backgroundColor = [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1];
}
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleDefault;
}
All my view controller are inheriting the baseViewController and all my navigation controller are inheriting the baseNavigationController.
UITabBarViewController -> BaseNavigationController -> BaseViewController
The issue is sometimes when my application is back from background and tap a cell (UITableView or UICollectionView), pushViewController do not work, and the app get stuck.Or sometimes only navigation bar pushed to next view controller,shows next view controller's title and the app also get stuck.The next view controller's viewDidLoad method is called.
I've worried for a week and I do not know why this is happened,so please help me to fix this odd issue.
Not 100% get this issue ,only sometimes.Thank you.
On iOS 8 I have a strange behavior regarding the navigation bar and orientation changes.
I have a navigation controller which reports a supported interface orientation UIInterfaceOrientationMaskLandscapeRight. The navigation bar has the expected height for landscape orientation (sadly I am not entitled to post screenshots).
Then I initiate a modal presentation of a view controller that only supports UIInterfaceOrientationMaskPortrait. When the presentation animation starts, it seems that the metrics of the underlying navigation controller are changed to a portrait presentation, as the height of the navigation bar grows to its portrait size, as depicted above.
iOS 7 does not exhibit this behavior. What am I missing? I want to restore the old behavior.
Here is the full code of the simple example above:
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
DOGButtonViewController *root = [DOGButtonViewController new];
DOGOrientedNavigationController *navi = [[DOGOrientedNavigationController alloc] initWithRootViewController:root];
navi.allowedInterfaceOrientations = UIInterfaceOrientationMaskLandscapeRight;
self.window.rootViewController = navi;
[self.window makeKeyAndVisible];
return YES;
}
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortrait;
}
#end
#implementation DOGOrientedNavigationController
- (NSUInteger)supportedInterfaceOrientations
{
return self.allowedInterfaceOrientations;
}
#end
#implementation DOGButtonViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = #"Button View Controller";
}
- (BOOL)prefersStatusBarHidden
{
return YES;
}
- (IBAction)buttonClicked:(id)sender
{
DOGPortraitViewController *vc = [DOGPortraitViewController new];
[self presentViewController:vc animated:YES completion:nil];
}
#end
#implementation DOGPortraitViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = #"Portrait Title";
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (IBAction)buttonClicked:(id)sender
{
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}
- (BOOL)prefersStatusBarHidden
{
return YES;
}
#end
In a more complex setup I also experience the text in a UIWebView contained in the navigation controller being scaled up when presenting the portrait modal. When dismissing the modal, the text is not resized to its original size.
For lack of a better option I've done a bit of a hack for this.
Basically before I show the modal view I take a screen shot and lay it on top of the presenting view controller.
Obviously I have to remove this screen shot when the view re-appears
func showScreenShot () {
let image = screenShot()
self.screenShotImageView = UIImageView(image: image)
self.view.addSubview(self.screenShotImageView!)
}
func screenShot () -> UIImage {
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, true, UIScreen.mainScreen().scale)
self.view.layer.renderInContext(UIGraphicsGetCurrentContext())
let image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image
}
func removeScreenShot () {
if let screenImageView = self.screenShotImageView {
screenImageView.removeFromSuperview()
self.screenShotImageView = nil
}
}
I'm trying to make an alert view so that upon selecting "Yes" (one of the buttons in AlertView), the user is directed to a new view controller with a button which I made via Storyboard. My code for the IBAction is as follows:
- (IBAction)alertButton:(UIButton *)sender
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Welcome Back to SymTrack!" message:#"Did you have reoccuring symptoms?" delegate:self cancelButtonTitle:#"No" otherButtonTitles:#"Yes", nil];
[alert show];
}
This is the code for the clickedButtonAtIndex which gives me the empty view controller without the button:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1)
{
UpdateViewController *updateVC = [[UpdateViewController alloc] init];
[self presentViewController:updateVC animated:YES completion:nil];
}
}
I've also tried these other codes for clickedButtonAtIndex but I got NSException for all of them:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1)
{
UpdateViewController *updateVC = [self.storyboard instantiateViewControllerWithIdentifier:#"UpdateViewController"];
[self presentViewController:updateVC animated:YES completion:nil];
}
}
or
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1)
{
UpdateViewController *updateVC = [self.storyboard instantiateViewControllerWithIdentifier:#"UpdateViewController"];
UINavigationController *alertNC = [[UINavigationController alloc] initWithRootViewController:updateVC];
[self presentViewController:updateVC animated:YES completion:nil];
}
}
note: all this code is within the view controller with the button that upon clicking brings the alert view up.
Thanks in advance!
Currently I am working with a UIWebview which shows web content provided from a user. In this content there will be links to other web content and I need to decide whether to open links in safari or in the UIWebview.
My current solution is to add a queryString to the URL in the html e.g. <a href=http://www.w3schools.com?StayInApp target=_blank>Visit W3Schools</a>
When the user presses the link the following method in the UIViewController decides how to open the link.
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSURL *url = [request URL];
NSLog(#"%#",url);
NSLog(#"%#",[url scheme]);
NSLog(#"%#",[url user]);
NSLog(#"%#",[url query]);
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
if ([[url query]isEqualToString:#"OutOfAppApp"]) {
NSLog(#"go out");
[[UIApplication sharedApplication] openURL:url];
return NO;
}
else if([[url query]isEqualToString:#"StayInApp"])
{
return YES;
}
}
return YES;
}
I do not have very much experience within web development and can therefore not see the consequences of using this approach. Is this a valid approach or should I use another way?
Regards
EDIT:
I have now come up with another approach using custom URL schemes, but I would still like comments on whether this is a valid solution :)
I have added a prefix to the links such as <a href=InAPP:http://www.w3schools.com target=_blank>Visit W3Schools</a>
When a user presses a link the app examines the prefix and decides whether to launch the rest of the url in the app or in safari. This is done with the following methods:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSURL *url = [request URL];
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
if ([[url scheme]isEqualToString:#"InAPP"]) {
NSLog(#"go in");
NSURLRequest *req=[NSURLRequest requestWithURL:[self removeExtensionFromURL:url]];
[[self browserView] loadRequest:req];
return NO;
}
else if([[url scheme]isEqualToString:#"OutAPP"])
{
NSLog(#"go out");
[[UIApplication sharedApplication] openURL:[self removeExtensionFromURL:url]];
return NO;
}
}
return YES;
}
-(NSURL*)removeExtensionFromURL:(NSURL*)url
{
NSMutableString *urlString=[NSString stringWithFormat:#"%#",url];
NSString *newURLString;
if ([[url scheme]isEqualToString:#"InAPP"]) {
newURLString = [urlString stringByReplacingOccurrencesOfString:#"InAPP:" withString:#""];
}
else if([[url scheme]isEqualToString:#"OutAPP"])
{
newURLString = [urlString stringByReplacingOccurrencesOfString:#"OutAPP:" withString:#""];
}
return [NSURL URLWithString:newURLString];
}