dynamically generated ui bar button needs to push to popover using segue - objective-c

zThis is based on a question I asked here which I have made good progressed already:
custom uitableviewcell will not display label texts
I basically followed the tutorial that was provided for me.
http://brianflove.com/2012/12/10/how-to-create-an-ipad-popover-view/
QUESTION
Now my issue is, I have to dynamically generate my ui bar buttons as if I just drag and drop it on the storyboard I am limited to one on the left and one on the right. This is my code to generate my button
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithTitle:#"Button" style:UIBarButtonItemStyleBordered target:self action:#selector(getMenu:)];
self.navigationItem.leftBarButtonItems = [[NSArray alloc] initWithObjects:btn, nil];
}
Based on that tutorial I need to use a segue to popover the uitableview that I need. But that will require me to have an anchor point like so
So my question is, how do I add an anchor point to that UIBarButtonItem? I've been searching and I keep finding something regarding creating a custom popover class? Is this accurate?

I solved this issue by creating an invisible UIView on the Navigation Bar itself and then use that as the anchor point for the segue. The issue with that is the "arrow" of the popover when the uiviewcontroller gets displayed is awkwardly placed. Still trying to figure that out.
This is where I got the answer from
https://stackoverflow.com/a/14514837/639713

Related

NSButtons Inside NSPopover View Controller

I've developed for Mac before but this is the first time I've attempted to use the NSPopover control, which seemed like a great idea to start out with but so far is causing me no end of problems. The applciation is a menu bar application. I have two NSButton objects in the NSPopover's view controller, the NSPopover is being created programmatically in another subclass of NSButton, the same button which it is being shown relative to. This NSButton that it is being shown relative to is contained along with some other buttons in an NSMenuItem
The popup, containing the two buttons, is being shown fine (see screenshot below), however, despite the 'Yes' button being highlighted with a focus ring, neither button responds to click events, they do not even graphically click in like I would expect them to.
And this is the code that creates the NSPopover and positions it onscreen:
someViewController *confirmationDialogue = [[someViewController alloc] initWithNibName:#"someViewController" bundle:nil];
popOver = [[NSPopover alloc] init];
[popOver setBehavior:NSPopoverAppearanceMinimal];
[popOver setBehavior:NSPopoverBehaviorTransient];
[popOver setContentViewController:confirmationDialogue];
[popOver showRelativeToRect:NSMakeRect(0, 0, self.frame.size.width, self.frame.size.height))
ofView:self
preferredEdge:NSMaxYEdge];
Has anyone got any kind of solution/workaround to this?
Thanks in advance :)
P.s. This is my first question on SO, so I hope I've provided enough information but I'll give any more details as needed.

Adding BarButtonItems to backButton in view controller

i have a view controller, which is standalone and has two left UIBarButtonItem, however when i push it, i want to have these two buttons + the back button
i tried
- (void)viewDidLoad
{
[super viewDidLoad];
// back
if (self.navigationController.navigationItem.backBarButtonItem) {
self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:self.navigationController.navigationItem.backBarButtonItem, self.barButtonFilter, self.barButtonFilterContacts, nil];
} else {
self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:self.barButtonFilter, self.barButtonFilterContacts, nil];
}
}
if there is a back button, than add, else replace
but i didnt work
I am not able to get your problem but according to your caption you want to replace you back button of UINavigationController with a bar button item, in that case you simply need to have a custom button in place of back Button:
UIBarButtonItem *backButton= [[UIBarButtonItem alloc] initWithTitle:#"yourTitle" style:UIBarButtonItemStylePlain target:self action:#selector(someFunction:)];
self.navigationItem.rightBarButtonItem = backButton;
[backButtonrelease];
If this is not your problem please elaborate.
So the issue here is that a UINavigationBar can only have one leftButtonItem and one rightButtonItem. But What you can do is in the center of the UINavigationBar you can have a UIView. You can use this to place the buttons on.
Someone has the code here: adding-buttons-to-the-titleview-of-navigationbar-without-having-to-repeat-code
From Apple's iOS Human Interface Guidelines:
Use a toolbar instead of a navigation bar if you need to offer a
larger set of controls, or you do not need to enable navigation.
Avoid crowding a navigation bar with additional controls, even if
there appears to be enough space. The navigation bar should contain no
more than a view’s current title, the back button, and one control
that manages the view’s contents. If, instead, you use a segmented
control in the navigation bar, the bar should not display a title and
it should not contain any controls other than the segmented control.
http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/mobilehig/UIElementGuidelines/UIElementGuidelines.html

Menu Accessible Throughout My App - How do I code this?

I have an app that's pretty much a large presentation of a companies product.
I have some additional functionality which I need to be accessible throughout my app.
The intended functionality for this toolbar is that it'll sit as a small, subtle tab along the bottom of the screen. When you tap the tab, the menu will expand upward (i.e. animate it's frame.y property), allowing you to tap any of the buttons contained within the menu.
The difficulty I'm having is that the app currently spans over several view controllers, and as I need this accessible throughout, in the interest of not duplicating code it would seem appropriate to make this ViewController also, that I would just load into my other view controllers, but this, by all accounts isn't recommended by Apple.
How can I build this menu functionality without duplicating code? I've tried a few things but cannot get the menu to display on my view.
Below, I'll show what I have at the moment.
Code that will sit on any view controller:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
ToolboxMenu *toolboxMenu = [[ToolboxMenu alloc] init];
[self.view addSubview:toolboxMenu.view];
}
Code that builds the toolbar:
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(#"Creating View");
self.view = [[UIView alloc] initWithFrame:CGRectMake(0,0,88,209)];
self.view.backgroundColor = [UIColor clearColor];
UIImageView *toolboxImage = [[UIImageView alloc] initWithImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"popup_toolbox" ofType:#"jpg"]]];
toolboxImage.frame = self.view.frame;
[self.view addSubview:toolboxImage];
}
In the above code, the NSLog fires when the menu is initialised, but I see no menu.
Rather than try to inject this into every view, I would recommend creating a separate UIWindow and float it over the main UIWindow. This is how the keyboard is implemented. Doing it that way will avoid any changes to any of the existing views. You will need to handle device rotation by hand for it, but that shouldn't be too difficult.
IIRC Apple's TabViewController was designed differently in that it's backwards to how you describe above. A TabViewController is the main or master ViewController with siblings being the display ViewControlers. Basically you have one TabViewController that will tab between views.
I would recommend you either redesign your view hierarchy OR extend UIViewController with a class that manages and displays the lower tab menu. Then you can easily init a single class that handles that in each of your views.

How to use a segmented control in the toolbar to switch views?

As it has been asked many times, I am trying to switch views by using a segmented control correctly. I cannot just hide/display because the views are too complicated.
I have gotten it to work using this solution from this answer, but this places the segmented control in the title bar. I would like to palce it on the bottom, in a toolbar.
I have tried hooking it up via IB and declaring each subviews control, but no luck. I think it has something to do with the #selector section.
Can someone please shed some light on this for me?
UIBarButtonItem *item = [[[UIBarButtonItem alloc] initWithCustomView:segmentedControl] autorelease];
// if you are in a navigation controller:
[self.navigationController setToolbarHidden:NO];
self.toolbarItems = [NSArray arrayWithObject:item];
// else, created a UIToolBar called toolBar at the bottom of the view and...
toolBar.items = [NSArray arrayWithObject:item];

How do I add a navigation bar's Done button to a popover's passthroughViews?

I'm working in an iPad app that has a split view with a navigation controller in the detail view. The deepest view that can be in the navigation stack is an edit view where the user can edit data. I put an edit button as the rightBarButtonItem and when editing starts, change it to a done button.
When editing commences and the user touches on a particular field, I present a popoverview with a list of possible choices filtered by what they are typing - a form of autofill based on all the values of that field in all other objects.
This works fine, except if you try touching on the done button. The popover eats this touch and dismisses itself. So the user has to touch done again.
I tried using the uipopovercontroller's passthroughViews property, but UIBarButtonItem is not a view and there is no documented way to get the view for the done button or even the navigation bar. I can access the variable in gdb, but it isn't accessible via KVC.
Any ideas on how I can prevent the need to tap done twice?
I've thought about a gesture recognizer on the window, but that seems messy and I'd have to handle rotation.
In case anyone gets here from google, copypaste from other question:
The only solution I found for now is to create UIBarButtonItem with custom UIButton using
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
//code for styling button
UIBarButtonItem *b = [[[UIBarButtonItem alloc]
initWithCustomView:button]
autorelease]
and then
popoverController.passthroughViews = [NSArray arrayWithObject:b.customView];
But be prepared - you cannot create UIButton that looks like UIBarButtoItem. I ended up with creating image that reassembled UIBarButtonItem.