Problem with UISPlitViewController toolbar - cocoa-touch

I'm trying to use a toolbar in a splitviewcontroller. For some reasons that are unknown to me, the table view on the left is not resized correctly.
If I turn to portrait and open the table view from the toolbar item and then go back to landscape view, the tableview is then displayed properly. I'm not sure why this happens.
This is what I have in the RootViewController:
self.navigationController.toolbar.items = [NSArray arrayWithObjects:... nil]; // Setting these to an empty array doesn't change anything
self.navigationController.toolbarHidden = NO;
self.navigationController.toolbar.barStyle = UIBarStyleDefault;
I doubt the bug is there, but the complete source code is available on github if there's something obvious to check.

I moved the code into viewDidAppear and it now works as expected.

Related

UITabBar moving selected image

I have two UITableViewControllers that needed to be shown in "swipable tabs". That means you can swipe left / right from one to another. I found a lot of similar questions and answers, but couldn't connect them together to produce a solution that would fit my needs.
The problem is that I need also a "selected image", that shows which tab is selected. This image should move (follow your finger) when you swipe to change tab. I found a project on git that solves my problem, the only thing is that it uses navigation controller instead of tab controller so I don't know how to change that.
Anyone already worked on a thing like this?
Example
https://github.com/cwRichardKim/RKSwipeBetweenViewControllers
You need to set swipe gesture recognizers for these actions.
UISwipeGestureRecognizer *returnToMainScreenSwipe = [[UISwipeGestureRecognizer alloc] initWithTarget: self action: #selector( returnToMainScreen:)];
returnToMainScreenSwipe.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer: returnToMainScreenSwipe];
And also selector
- (void)returnToMainScreen:(UISwipeGestureRecognizer *)gestureRecognizer
{
[self.tabBarController setSelectedIndex: MIDDLE_TAB];
}

iOS 8 - Modal in Popover

I have a popover with TabBarController in it. In one tab there is a TableViewController with a list of names. And there is a plus button, that has a modal segue to AddCharacterVC for adding new names.
In iOS 7 I do it like this:
AddCharacterViewController *acvc = (AddCharacterViewController *)segue.destinationViewController;
acvc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
acvc.modalPresentationStyle = UIModalPresentationCurrentContext;// so it does not take full screen in popover
And in AddCharacterVC I set content size like this:
- (void)viewWillAppear:(BOOL)animated {
CGSize size = CGSizeMake(320, 480); // size of view in popover
if (IDIOM == IPAD && [self respondsToSelector:#selector(preferredContentSize)]){
self.preferredContentSize = size;
}
And it works perfectly.
However, in iOS 8 modal view does not cover the whole popover, leaving TabBar visible. The user can tap on it or not, anyway modal view won't unwind properly.
I've tried:
setting acvc.modalPresentationStyle to UIModalPresentationOverCurrentContext
tried to set TabBar hidden
checked in storyboard that edges of TableVC extend under Bottom Bar and Bottom Bar in Modal View (AddCharacterVC) is set to none
All with no results.
Now the only thing I can think of is to try making modalPresentationStyleCustom and use UIPresentationController (I'm trying to do it now, but I haven't done it before). Am I missing something? Could there be other way to do it? Sorry, I cannot post images here yet. Many thanks in advance!
Ok, so I've set the modalPresentationStile to UIModalPresentationCustom, and used UIPresentationController - I've just copied code from WWDC-14's LookInside project and modified it a bit.
I'm not sure if it was the best solution, but it worked in my case.

backBarButtonItem with popViewController and swipe

My App logic is like that: VCA => VCB, and there is a scroll view in VCB with swipe left and right function. Some code help to understand structure, in VCB:
self.scrollView.pagingEnabled = YES;
self.scrollView.directionalLockEnabled = YES;
self.scrollView.contentSize =CGSizeMake(CGRectGetWidth(self.scrollView.frame) * numberPages, CGRectGetHeight(self.scrollView.frame));
so what I want is list some pages horizontally and swipe to left and right to navigate. Each page has it own view controller(child view controller of VCB) and I add them like that:
if (controller.view.superview == nil)
{
[self addChildViewController:controller];
[self.scrollView addSubview:controller.view];
[controller didMoveToParentViewController:self];
}
So far it works fine for iOS 6. I can swipe to change page. All function inside each page also works fine.
Then the problem comes with iOS 7's new feature, swipe to right to automatically call popViewControllerAnimated:, same effect like click go back button. To solve the conflict, I disable the interactivePopGestureRecognizer: self.navigationController.interactivePopGestureRecognizer.enabled = NO;
and it works ok, no force to pop back when I just want to swipe change the page.
Now the real problem. I set a back button(backBarButtonItem) on navigation bar. Every time I use that button pop from VCB back to VCA and current page is not the first page (that means there is at least one page on the left side), the pop animation is like first change page to the left side one, then immediately show VCA without any animation.
So any solution? Please help me.
First of all, it is hard to determine the problem without any piece of your code.
And secondly, why won't you create the button yourself, and add a target to it, a function that'll dismiss / pop the view controller?

UINavigationBar Back button with no text, ever

I have a requirement in a project that the UINavigationBar Back button should never have text in it, it should always just be a left arrow.
By default iOS is going to insert the title of the previous controller in there. Is there any way I can stop this from happening across the whole app?
(I know I can do this screen by screen, but I'm working on an existing app with A LOT of screens it and this would be a big job)
You can always set an image of an arrow to left bar button of navigation bar
// ADDING IMAGE TO BUTTON
UIButton *refreshButton = [UIButton buttonWithType:UIButtonTypeCustom];
[refreshButton setFrame:CGRectMake(0,0,30,30)];
[refreshButton setImage:[UIImage imageNamed:#"arrow_image.png"] forState:UIControlStateNormal];
refreshButton.userInteractionEnabled=NO;
// ASSIGNING THE BUTTON WITH IMAGE TO LEFT BAR BUTTON
UIBarButtonItem *refreshBarButton = [[[UIBarButtonItem alloc] initWithCustomView:refreshButton] autorelease];
self.navigationItem.leftBarButtonItem = refreshBarButton;
You will have to write this in each view controller in order to disable default left bar button.
You can't stop it from happening across the whole app, you'll have to set it manually in each controller. You could use a category on UIViewController and call that method in each controller, which will get you down to 1 line of code that doesn't have to change if you change your approach. Still sucks, I know. Also, you will probably have issues with Apple if you do that. We tried that in one of our apps and when I showed it to the Apple guys at WWDC '13 they flat out told me they would reject the app if I submitted it that way. YMMV

presentModalViewController slides a new view too far up and goes above the top of the screen

-(void)reviewClicked:(id)sender
{
ReviewViewController *newView = [[ReviewViewController alloc] init];
newView.delegate = self;
UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:newView];
[self presentModalViewController:navCon animated:YES];
}
I have a splitViewController setup, which is what is probably causing some issues. Within the detail view controller, I have a button that when clicked calls the above code.
The goal is to slide a view from the bottom of the screen upwards so the user can review their selections, and then click a button to return back to the original detail view. This code is working and you can click back and forth between the modal view and original detail view.
The problem is, after it slides up the screen, it continues sliding past where it should stop, and finally stops a good 10-15 pixels too far up. Basically, this modal view slides in so far up that a good chunk of the view goes above the top of the screen. Meanwhile, that same amount of space is "empty black space" at the bottom of the screen, just further suggesting that the view just simply moved too far up.
Complicating matters, it slides in just fine in landscape mode.
So the question is, does anyone know why this bug is occurring to make the modal view slide too far up and past the top of the screen?
-=-=-=-=-=-=-
Edit:
Sorry about that, I meant to type navCon in that spot. I fixed it above.
-=-=-=-=-=-=-
Solution:
-(void)reviewClicked:(id)sender
{
ReviewViewController *newView = [[ReviewViewController alloc] init];
newView.delegate = self;
UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:newView];
navCon.view.frame = CGRectMake(0, 0, 768, 1080);
[self presentModalViewController:navCon animated:YES];
}
After some trial and error, I realized I had never actually set the frame of the view! A solution as simple as that...I had been running through examples that included .xib files, and since those files created the frame automatically, I totally overlooked it!
Keep in mind for anyone looking at this in the future. This frame is for portrait mode only. If you want landscape mode, just modify the frame accordingly:
navCon.view.frame = CGRectMake(0, 0, 1080, 768);
Although I had found a quick solution to the problem as described in the question. The fact is, there were many problems still around. Upon further inspection, I called upon the appDelegate to call these methods:
[self.splitViewController presentModalViewController:navCon animated:YES];
[self.splitViewController dismissModalViewControllerAnimated:YES];
Basically, I had the root view class call the modal view which solved ALL of my issues. Apparently calling a modal view from within the detail view of a splitview is NOT the same as calling a modal view from the root view (which happens to be the splitViewController). I hope this helps anyone in the future. Cheers.
-=-=-=-=-=-=-=-
For more reference, see this post I stumbled upon:
UISplitViewController - Pushing Modal View