iOS presentViewController breaks autolayout - ios8

I have a TableView on top of a ViewController.
When I tap a row, I load a PDF Reader using:
ReaderViewController *readerViewController = [[ReaderViewController alloc] initWithReaderDocument:document];
readerViewController.delegate = self; // Set the ReaderViewController delegate to self
readerViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl;
readerViewController.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentViewController:readerViewController animated:YES completion:nil];
But when I come back, my layout seems to be broken:
I have tried solutions like:
Frame doesn't reflect auto layout constraints after dismissing modal view controller
iOS AutoLayout issue with ScrollView
But I can't still solve my issue. What do you recommend? Thanks

Related

UISearchBar cannot become first responder after UITableView did re-appear

I have an iPhone app for iOS8. UIPageViewController has a child view of UITableViewController, and that's where I put UISearchController.
When the UITableViewController is presented for the first time, I have no trouble activating the search by doing
[self.searchController.searchBar becomeFirstResponder];
However, once the view controller gets invisible either by pushing to another table view controller, or modally presenting a UIViewController (visually masking it), the searchBar can no longer become first responder after it reappears.
The search itself can be done by
[self.searchController setActive:YES];
but, there is no caret blinking this way (user has to tap inside searchBar to start typing).
I have almost identical UITableViewController with UISearchController without the incident. So, I must be missing something, but I would like your opinion on which direction I should pay attention on solving this.
Below is how I set the search controller.
#interface MonthTableViewController () <UISearchResultsUpdating, UISearchControllerDelegate>
#property (nonatomic, strong) UISearchController *searchController;
UITableViewController *searchController = [[UITableViewController alloc]initWithStyle:UITableViewStylePlain];
searchController.tableView.dataSource = self;
searchController.tableView.delegate = self;
self.searchController = [[UISearchController alloc] initWithSearchResultsController:searchController];
self.searchController.searchResultsUpdater = self;
self.searchController.delegate = self;
self.searchController.searchBar.frame = CGRectMake(self.searchController.searchBar.frame.origin.x, self.searchController.searchBar.frame.origin.y, self.searchController.searchBar.frame.size.width, 44.0);
self.tableView.tableHeaderView = self.searchController.searchBar;
self.definesPresentationContext = YES;
// Hide search bar
CGRect myBounds = self.tableView.bounds;
myBounds.origin.y += self.searchController.searchBar.frame.size.height;
_lastlyAddedTableBoundY = self.searchController.searchBar.frame.size.height;
self.tableView.bounds = myBounds;
I solved it by going Xcode > Product > Analyze.
I simply forgot to add
[super viewWillAppear:(BOOL)animated];
inside -(void)ViewWillAppear:(BOOL)animated on the corresponding UITableViewController.
Hopefully, my mistake can save someone's time in the future.

ipad: keybord at wrong position

When I have switched to another view (After returning from taking a picture or after switching to a view to select stuff in table) the ipad keyboard appears at the wrong position.
When I select a text field, I see this on my Ipad and on the simulator. (can't post images yet). If I turn my ipad (so that it aligns horizontal) and rotate back the keyboard is back normal.
https://devforums.apple.com/servlet/JiveServlet/showImage/2-701040-19966/Screen+Shot+2012-07-20+at+16.36.20.png
My code to switch to the camera for taking a picture...
- (IBAction)getCameraPicture:(id)sender
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.title = #"CameraPicture";
[self presentModalViewController:picker animated:YES];
}
My code to switch to a view with a table in it :
[self presentModalViewController:viewControllerSpanoTechProducts animated:YES];
code for returning after selecting stuff :
[self dismissModalViewControllerAnimated:YES];
how my app works: you have a main screen with buttons and textfield to fill in a form. when you push a button to select a product I switch to another viewcontroller with a table where you can select a product and a button 'done'. If you click the 'done' button I switch back to the original view.. hope this helps?
I'm just started with iOS.. Any help is appriciated!
At the time of switch user this code:
[yourTextFieldObject resignFirstResponder];
This might work.

How to dismiss a TableViewController within code called by a storyboard push segue?

I know how to handle push segues in Storyboard and the use of the back button that is created with the navigation controller. I have one main tableview connected to a child tableview via push segue in Storyboard. Works fine for switching between tables.
I want to add the ability to also gesture swipe left in the child tableview to return to main tableview.
First tried this within Storyboard with the use of the swipe gesture recognizer, but this caused the main tableview to become a new child to the child tableview.
I then tried within code:
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
... but this seems to only work with a modal segue
I have:
- (void)viewDidLoad
{
[super viewDidLoad];
UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleSwipe:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
[self.tableView addGestureRecognizer:recognizer];
}
- (void)handleSwipe:(UISwipeGestureRecognizer *)gestureRecognizer
{
// need code here to dismiss the child tableview
}
Finally figured it out today and it works perfectly:
- (void)handleSwipe:(UISwipeGestureRecognizer *)gestureRecognizer
{
[self.navigationController popViewControllerAnimated:YES];
}
Found answer in:
iOS Developer Library > UINavigationController Class Reference > popToViewController

How to create NSTextField programmatically?

I want to create NSTextField programmatically. I am new to Mac App Development.
Can anyone help me in this ?
Update :
I tried this code
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSView *myView = [[NSView alloc] init];
NSRect frameRect = NSMakeRect(20,20,100,140);
NSTextField *myTextField = [[NSTextField alloc] initWithFrame:frameRect];
[myView addSubview:myTextField];
}
This does nothing. Please correct me if i'm wrong anywhere.
Thank you.
Creating UI elements programmatically is very simple in Cocoa.
It involves two steps:
Create the view and set a frame to it.
Add it as a subview to any super view.
Following snippet will you help you understand better.
NSRect frameRect = NSMakeRect(20,20,40,40); // This will change based on the size you need
NSTextField *myTextField = [[NSTextField alloc] initWithFrame:frameRect];
[myView addSubview:myTextField];
It looks like you're creating an NSTextField OK, but you're not adding it to anywhere visible in the view hierarchy. Your app probably contains one or more NSWindow instances; if you want a view to appear in a particular window, you should add it as a subview of that window's content view.

Use NSScrollView together with Cocos2d-mac (NSOpenGLView)

Has anybody used a NSScrollView to control scrolling using the cocos2d-mac framework?
After much struggling I managed to make UIScrollView work with cocos2d-ios. Any pointers to using NSScrollView together with a NSOpenGLView would be appreciated.
I finally managed to get a NSScrollView working within my cocos2d-mac Xib.
The trick is that you have to programmatically overlay the OpenGLView over the NSScrollView main view (leaving room for the scroll bars) by first setting up a fake view as the scrollView's documentView, and then removing the openGLView from its parent view and adding it again (so the OpenGLView is drawn over the ScrollView). You can do it as follows:
appDelegate = [[NSApplication sharedApplication] delegate];
// Set up NSScrollView with dummy empty view as big as the layer
NSRect rect = NSMakeRect(0, 0, myLayer.width, myLayer.height);
NSView *view = [[NSView alloc] initWithFrame:rect];
appDelegate.scrollView.documentView = view;
[view release];
// Push OpenGLView back to front
[appDelegate.glView removeFromSuperview];
[appDelegate.splitLeftView addSubview:appDelegate.glView];
And then, you should use the scroll bars events to update the myLayer position accordingly.

Resources