Dismissing MWPhotoBrowser View controller Modally in Split View - xcode

Ran into a snag and hoping for some insight here.
Overview: Universal app. The iPhone portion works great. The iPad portion has a split view controller. The master is a table view (left side) where the user selects a row and displays its detail (right side). Pretty standard stuff.
I’m using Xcode version 4.4.1 and my project is using Core Data, Storyboards and ARC.
DetailViewController: On the detail is a button that brings up another table view (within the detail) of user notes by date with a custom view. Each note can have an image associated with it. If a note has an image then a button with its photo icon is shown.
Example screenshot up to this point:
MWPhotoBrowser: When the button of the photo icon is pressed I call MWPhotoBrowser (a wonderful library to show images in a standard way) to display the image or images. Single tap shows the one selected image, a double tap shows all images on the current table with the one chosen being viewed first. The image is displayed full screen.
To show the photo browser I use this code:
// Create the browser view.
MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
// Set browser options.
browser.wantsFullScreenLayout = YES;
browser.displayActionButton = YES;
[browser setInitialPageIndex:self.buttonRow];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:browser];
[self presentModalViewController:navController animated:YES];
The navController allows me to include a navigation controller with a “Done” button which calls doneButtonPressed.
Issue: All of the above works well until I press the “Done” button. The full screen photo browser dismisses properly. Unfortunately, the table view on the right side from where the user pressed the photo icon button is now gone (black). I thought the NotesViewController (right side) would remain there after photo browser was dismissed modally. Does calling a model view controller in a split view cause the other view controllers to be deleted?
Example screenshot showing problem:
The stacks on the detail view controller (right side) should be DetailViewController > NotesViewController > then call MWPhotoBrowser modally. After the photo browser is dismissed my self.navigationController.viewControllers.count equals 1 and I was expecting it to be 2.
Here’s the code that dismisses the MWPhotoBrowser:
- (void)doneButtonPressed:(id)sender {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[self dismissViewControllerAnimated:YES completion:nil];
}
.
.
.
Hope someone can help me wrap my head around this.
As always, any help is greatly appreciated. Thanks!

I resolved my issue within the NoteViewController (the area turning black after the MWPhotoBrowser was dismissed).
Within viewWillAppear I was setting my tableview to nil (to prevent cell overwrap) and reloading my table data.
self.tableView = nil;
[self.tableView reloadData];
This works fine for the iPhone and when not returning from the MWPhotoBrowser’s full screen display on the iPad. For some reason that I do not understand, the above code causes the issue. I added additional logic to check if I’m returning from the full screen display and now all is fine. I’ll look into it more when time permits.

Related

ViewController canBecomeFirstResponder iOS 8

I have a VC that has an inputAccessoryView that is used to display a textfield (much like the messages app). When I push this view onto the navigation stack everything works fine and by that I mean that the tableview adjusts its insets to make sure nothing scrolls underneath that accessory view. However, if from that view I push on another instance of the same view controller class the insets will not be adjusted and the scrolling of the table will be behind the accessory view.
This issue is seen in iOS 8 only. The other interesting thing about this is that if you then click in the accessory view to open the keyboard the insets are adjusted properly for the keyboard being visible and again when it's hidden.
Also if you don't click the text field to fix the issue and hit back the previous VC is broken as well.
I'm fairly certain based on the information above that this is an iOS 8 bug. I'm hoping someone has seen this and come up with semi reasonable fix.
Nasty solution but a solution nonetheless:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.inputAccessoryView.inputAccessoryTextField becomeFirstResponder];
[self.inputAccessoryView.inputAccessoryTextField resignFirstResponder];
});
}
This allows the view to redraw the insets

Changing custom view with button that is within the views themselves

I have so far managed to create an imageView with a picture in order to create a background. (This takes up the whole window) I now want to switch to several views using buttons that are on top of this image! So far I have found many tutorials that show how to create a custom view and have buttons bellow in the NSWindow, but am unable to get my head around how to do it if the button is actually within the custom view.
The aim is to have the start up view which has a button saying "start game" clicking it will swap to a new view which again will have numerous buttons which will again switch to various other views.
I am new to Xcode and to this forum so if it has already been described somewhere please don't have a go, just point me in the direction. I have searched far and wide so it is not down to lack of effort.
Set tag on button click..so that images can identified.
-(IBAction)editImage:(id)sender
{
UIButton theButton = (UIButton)sender;
if (tag==1) {
[theButton setImage:[UIImage imageNamed:#"image1"] forState:UIControlStateNormal];
[theButton setTag:2];
}
else if (tag==2){
[theButton setImage:[UIImage imageNamed:#"image2"] forState:UIControlStateNormal];
[theButton setTag:1];
}
}
Hope this will help you

Unable to show re-order controls on a UITableView shown in a popover controller

I am working with a universal app and am using storyboards. The basic idea of the app is there is a text view inside of a navigation controller. After the user edits the text view, they have the option to save the data. This text view data is saved in an array. To view the list of saved text views there is a button in the navigation bar, which when pressed segues to a table view. The problem I am having is on the iPad version, this table view appears as a popover and doesn't inherit the navigation bar, which shows the edit button allowing for the cells to be reordered. I am at a loss for finding a solution to show the re-order controls for this table view when in a popover. This works fine of the iPhone version since the table view segue is a push.
Here is the segue code for the popover:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"Show Digital Tape Archive"]) {
if ([segue isKindOfClass:[UIStoryboardPopoverSegue class]]) {
UIStoryboardPopoverSegue *popoverSegue = (UIStoryboardPopoverSegue *)segue;
[self.popoverController dismissPopoverAnimated:YES];
self.popoverController = popoverSegue.popoverController;
} .....
Any help or suggestions appreciated.
After researching and a lot of trial and error, the solution I came up with is creating this popover as a UIViewController instead of a UITableViewController. I then added a toolbar and a tableView. When I originally created this viewController, it was a UITableViewController and I wasn't able to add a toolbar.
There appears to be a way to add a toolbar on a UITableViewController but wasn't able to do it.

Navigation Bar Layout Issue on Tab Bar Controller + Navigation Controller

I've followed a how-to to create a simple Tab bar controller with a navigation controller in the first tab. Until here all is working correctly, expect a strange issue on the layout.
When the app starts the first time, the Navigation Bar on the top of the first loaded nib is a little outside of the view. I cannot figure out why this happen. In the first view there is a button "Add new System" that opens a modal view. If I press this button and the modal view appears and then I dismiss the modal going back to the initial view, then the Navigation bar at the top is placed/refreshed correctly. The same happens if I press the second TAB (it's a simple nib without Navigation controller for now) and then back to the first TAB, the Navigation bar is placed in the correct position.
Here a screenshot on the first startup:
And here when I press the modal view or the second TAB and then back to the first view:
The code is quit simple following one of the numerous tutorials on the net. I'm NOT using storyboard. Only customization was adding the buttons on the top of the Navigation Bar:
UIImage *editbuttonImage = [UIImage imageNamed:#"edit_pressed.png"];
UIButton *editButton = [UIButton buttonWithType:UIButtonTypeCustom];
[editButton setBackgroundImage:editbuttonImage forState:UIControlStateNormal];
editButton.frame = CGRectMake(0, 0, editbuttonImage.size.width, editbuttonImage.size.height);
[editButton addTarget:self action:#selector(leaveEditMode)
forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
initWithCustomView:editButton];
[editButton release];
[editbuttonImage release];
No other modifications were made. The nib was used before in a single view. Then I've tried to insert it into a TAB Controller + Navigation Controller.
I could post the whole code in case it's needed. Under Select System there is a Table View, in these pictures empty, also not shown.
Thank's for the help!
Simon
I've solved the issue myself. On startup I've setup to hide the status bar and shown it again in the app delegate. The directive used :
[[UIApplication sharedApplication] setStatusBarHidden:NO];
was after adding the navController as subview. Also the Navigation controller BAR was not out of the view, simply under the status bar.
Hope this helps someone :)
Cheers, Simon

Resizing view controller acording to tabbar controller

In my application, I have developed one wizard in which I am providing a way for the user to setup his details one-by-one. After finishing all steps, the user will be redirected to the screen where TabBar will come into the picture.
The problem here is that the user can access the same view controllers with the wizard (without TabBar controllers) and normal flow (which is with tabbar controller). In the wizard, I am using a view controller of size 320x480 and the same in normal flow. But whenever I load any view controller using TabBar the 44 pixel view from bottom side gets hidden behind TabBar.
I know the I can manually set the view size, by detecting whether TabBar is present or not, but here in this case number of view controllers are more and its already designed of size 320x480.
I had tried with all methods given in Apple's documentation but none of it seems to work for me.
Following are the methods I have tried, along with some xib settings.
[self setWantsFullScreenLayout:YES];
self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight;
[self.view setAutoresizesSubviews:YES];
[self.navigationController.view setNeedsLayout];
Is there any way to set the height of a view controller according to whether that TabBar is present or not?
In my case, (Status bar/Nav bar/Hidden tabbar) this worked
//Add this in your ViewController
self.edgesForExtendedLayout = UIRectEdgeBottom;
self.extendedLayoutIncludesOpaqueBars = YES;
However Barry's answer is better if you use Storyboard but I could not for this VC.
Tried for iOs7 and iOs 8.
If you're using storyboards, select each tab VC and clear the box for View Controller > Extend Edges > Under Bottom Bars.
I wasn't able to find a good answer for this, so I ended up adding a BOOL, hasTabBar. I set it true or false based on where I create my view, and use that to calculate my layouts.
frame.size.height -= (hasTabBar*50); // works nicely.

Resources