Xcode: UINavigationController in a subview - xcode

I'm new in Xcode (and also here, in stack overflow) and I'm trying to build an application which contains a small UINavigationController (with a TableView inside) on the top of the window. So it should not be in full screen, it's just a little part of the GUI (just like a textField, or any other kind of component).
I've read that UINavigationController is designed to be displayed on the entire screen, but would it be possible to do it anyway?
If I can't, I'll probably have to write my own UINavigationController-like and TableViewController-like, with all transition effect (between 2 TableView) etcetera...
Thanks in advance for your help!

I founded the solution in a book and it's quite simple. I have to create the UINavigationViewController programmatically:
tableViewController = [[MyTableViewController alloc] initWithNibName:#"MyTableViewController" bundle:nil];
navCtrl = [[NavigViewController alloc] initWithRootViewController:tableViewController];
[navCtrl.view setFrame:CGRectMake(40, 40, 150, 200)];
[window addSubview:navCtrl.view];
[self.window makeKeyAndVisible];

Related

iOS 9 Bug when using presentViewController "EXC_BAD_ACCESS code=2"

First. IT WAS working until this last update from Apple. So in theory it should still work.
Here's the code:
CarouselViewController *cViewController = [[CarouselViewController alloc] initWithContent: edition];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController: cViewController];
[self presentViewController: nav animated: YES completion:nil];
The reason i'm doing it is because i need this new window to be presented in fullscreen and not inside this ViewController (the caller) which is occupying half of the screen.
So, HOW can i fix this? And why BEFORE it was working and now with this silly iOS 9 update it isn't?
My guess (and that's all it is with the limited information presented) is that the root cause of the problem has something to do with CarouselViewController and it's view actually being loaded and presented on screen.
That is what is happening in your app during this line
[self presentViewController: nav animated: YES completion:nil]
I would set a breakpoint in that ViewController subclass loadView/viewDidLoad or check out it's Nib/Storyboard.

Paging in MWPhotoBrowser not working properly after implementing custom tabbar

I'm using MWPhotoBrowser in a project and everything worked great until I implemented a custom tabbar (to make one of the tab items higher and wider). I used RXCustomTabBar as a starting point for my tabbar and only modified it a bit, no meaningful changes though.
After implementing the new tabbar and in the app open the MWPhotoBrowser I can only view the first photo. I can still scroll in the photobrowser but no other photos than the first is shown. Neither can I toggle the "fullScreenLayout" that is implemented in the MWPhotobrowser when I'm not viewing the first photo.
I'm simply confused since I have no idea what is causing this problem. I know it's a far fetched question since it's two custom made libraries I'm working with but perhaps someone has experienced a similar problem in the past. Would be very grateful for suggestions!
This is the code I use to push the MWPhotoBrowser:
MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
[self.navigationController pushViewController:browser animated:YES];
I tried presenting the browser modally with:
[self.navigationController presentModalViewController:browser animated:YES];
That way the photos are shown correctly but I have no navigation bar.
After hours of headache I came up with a solution:
MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
[browser setInitialPageIndex:indexPath.item];
UINavigationController *navBar = [[UINavigationController alloc] initWithRootViewController:browser];
[self.navigationController presentModalViewController:navBar animated:YES];
I.e. I create a UINavigationController in which I embed my MWPhotoBrowser and then present the navigationcontroller modally.

NSTextField unable to gain focus on NSStatusItem when shown in NSPopover

It seems as if this has been a reported bug already (http://openradar.appspot.com/9722231), but is there a way to get around it? Or is there an alternative to the NSPopover that can be used to create the same kind of interface?
Thanks in advance
Here's some code:
Popover creation
popover = [[NSPopover alloc] init];
popover.contentViewController = popover_controller;
popover.appearance = NSPopoverAppearanceMinimal;
popover.animates = YES;
popover.behavior = NSPopoverBehaviorTransient;
popover.delegate = self;
Displaying the Popover
[popover showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMaxYEdge];
The sender is the NSStatusItem. The popover is displayed just fine, but if you try to click on the NSTextField, you are unable to edit the text or just gain focus in general.
So it turns out that this is a core OS bug and the only way around it was to use a custom NSWindow that looks like an NSPopover. I decided to use MAAttachedWindow.

ios4 - Load new view on clicking a button

I am currently using XCode 3.2.3 and iOS4. I'm working on an app that simply starts with one screen and on a button click moves to the next.
I have gone thorugh the ViewController programming guide and a post here.
What I am doing is very similar to whats happening on the post. So let me explain the steps, I followed:
In IB, drag and drop, a View from the library into the editor. I renamed the new UIView to myView.
In my AppControllerDelegate, I added the new view "myView" as a property of the view controller (File's Owner). I synthesized it as well in the implementation.
Now, in the implementation of the ViewController, within the button pressed action handler, I wrote the following lines of code:
[self.view addSubView: myView];
On clicking the button however, I do not see a new screen or my new view. However if I do this, I get a new screen or new view:
UIView *anotherView = [[UIView alloc] initWithFrame:self.view.frame];
[self.view addSubView: anotherView];
I do know that the best way is to do it with separate NIBs for each UIView. However, I am new to iPhone development and have not explored that path as yet.
My question: What am I missing upto step 3?
One way you could be able to do it is by trying it this way
myView = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle: [NSBundle mainBundle]];
[self.view addSubview: myView.view];
Try that and see if it is working.. if yours is a view based project then instead of [self.view addSubview: myView.view], just give [self.view addSubview : myView];

How to customize / style a UIPopoverController

I'm working on an iPad application and I'm using UIPopoverControllers. I'm at the part where the app needs to be branded and styled and i'm wondering how to change the color / tint of the UIPopoverController? Standard is dark blue but it needs to be another color..
is this possible?
Greets, Thomas
This is possible starting in iOS 5.0 by subclassing the abstract class UIPopoverBackgroundView and assigning your subclass to the popoverBackgroundViewClass property on your UIPopoverController instance. Unfortunately there is no tintColor property as the popover needs to use images for it's arrow and border in order to achieve smooth animations during dynamic resizing. You can learn more about how to customize the appearance of a UIPopoverController in the UIPopoverBackgroundView Class Reference
It's impossible for now.
It's what I call the "Box in a Box" model. You get control of the box inside of the box (the UIViewController inside of the UIPopoverController), but you have very limited control over the actual popover itself. Outside of the arrow direction and the size, you can't change much else. There are also options for a modal effect popover, which dims everything else when it shows up, but I haven't tried to get it working.
I'm sure you've noticed there is no UIPopover class by now.
The answer you want to hear:
If you really want to style one that bad, just write your own. It's really not that hard.
The link you want to click:
Cocoacontrols is an index of iOS and OSX components available on GitHub, they have some popover stuff.
iOS 7 introduces backgroundColor property of UIPopoverController which affects/includes the navigation background color as well as arrows of popover.
#property (nonatomic, copy) UIColor *backgroundColor NS_AVAILABLE_IOS(7_0);
Usage example:
if ([self.popoverVC respondsToSelector:#selector(setBackgroundColor:)]) { // Check to avoid app crash prior to iOS 7
self.popoverVC.backgroundColor = [UIColor greenColor]; // [UIColor colorWithPatternImage:#"..."] doesn't reflect the color on simulator but on device it works!
}
Note - As of now (iOS 7.0.3), in some cases (like set color using colorWithPatternImage:), the simulator (and even some devices) doesn't honor the color.
Throwing my hat in here;
I've leveraged UIPopoverBackgroundViews in iOS 5+ to add a simple tintColor property onto UIPopoverControllers.
PCPopoverController: https://github.com/pcperini/PCPopoverController
I try to trick it by customizing the view controller inside the popover and then hiding the popover border using this code:
UIView * border = [[insideViewController.view.superview.superview.superview subviews] objectAtIndex:0];
border.hidden = YES;
The app is actually still in development so I'm hoping other people will comment on this solution.
check out these latest projects leveraging UIPopoverBackgroundView
https://github.com/CRedit360/C360PopoverBackgroundView
https://github.com/GiK/GIKPopoverBackgroundView
from ios 5 onward it is can be done, here is a library
https://github.com/ddebin/DDPopoverBackgroundView
just look at the documentation , and it is quite easy
good luck
You can use Elegant Popover cocoapod for just that. You can customise shape and colour of the arrow and the popover itself. Also, you can add colourful borders to the popover.
I know this is a lousy constructed answer, but I've just been playing with the UIPopoverController's views. They do exist.
The only way to access them is from your view that is sitting in the UIPopovercontroller.
I have a navigation controller so I follow this hierarchy
UIView *test = ((UIView *)[[[self.navigationController.view.superview.superview.subviews objectAtIndex:0] subviews] objectAtIndex:1]);
UIView *test2 = ((UIView *)[[[self.navigationController.view.superview.superview.subviews objectAtIndex:0] subviews] objectAtIndex:1]);
test.backgroundColor = [UIColor greenColor];
test2.backgroundColor = [UIColor greenColor];
This isn't exactly the end goal, but it is really close.
you'll find that the_view_in_the_popover.superview.superview (maybe just one superview if you are not reaching out from a navigation controller view) is a UIPopoverView. If you cast it as a UIView and treat it as a UIView you're not really breaking any rules. I guess that is really up to apple though.
Remove UIPopoverController border:
NSArray* subviews = ((UIView*)[popupController.contentViewController.view.superview.superview.superview.subviews objectAtIndex:0]).subviews;
for(UIView *subview in subviews){
[subview removeFromSuperview];
}

Resources