NSButtons Inside NSPopover View Controller - objective-c

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.

Related

dynamically generated ui bar button needs to push to popover using segue

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

Why is my UIActionSheet hidden by my TabBarController?

I am having a problem correctly implementing a UIActionSheet in an iPad 5.1 (XCode 4.3) project. I can populate it correctly with all the items I need. The list is longer than the window, but the scrollbars automatically come up, etc. However, the cancel button (which I presume is supposed to be at the end) is coming up half hidden behind my tab bar. Shown below:
(sorry, SO won't let me post images yet)
Here is my storyboard setup:
The entry point is that Tab Bar Controller on the left, which goes to another Navigation Controller (center), which has the View Controller on the right as the root view.
http://i854.photobucket.com/albums/ab103/srVincentVega/ScreenShot2012-06-28at52713PM.png
I have tried presenting the UIActionSheet in all sorts of ways, but this odd behavior persists, and I can't figure out how to address it
- (IBAction)cmdReason:(id)sender
{
NSArray *reasons = [AppState getInspReasons];
UIActionSheet *action = [[UIActionSheet alloc]
initWithTitle:#"Reason for Inspection"
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:nil];
for (NSString *rsn in reasons)
{
[action addButtonWithTitle:rsn];
}
[action showInView:self.view];
}
I have tried the various methods to show "action" - showFromTabBar, showFromToolbar, etc - I am VERY new to this development environment, so I am not up to speed yet on how these items interact at this level. Does anyone have a suggestion for how I can present this correctly?
I am sorry if this has already been asked elsewhere. I have spent all day trying bits of code from all over the web, including SO. I don't know if it's something to do with my storyboard layout, or what.
One further thing - when I rotate the emulator, the action sheet does redraw, but the bit at the end there gets wonky looking, like it can no longer figure out how to draw it.
Many thanks!
EDIT:
I have put together a very small project that demonstrates this exact behavior. I don't have a good way to host the zip file, so I put on google docs and shared it. The link is below. If you click on that, there should be a download option under file that will give you the original zip file.
https://docs.google.com/open?id=0B7IYvy9_c_NLaEFneGc5bzc2S2c
Seems like there is not a real solution for this. It looks like it's a limitation with UIActionSheet if you add that amount of button titles and present that from a tab bar.
Beside that, the proper way to display an UIActionSheet from a tab bar is to use
[action showFromTabBar:self.tabBarController.tabBar];
instead of
// Taken from your example project
AppDelegate *d = [[UIApplication sharedApplication] delegate];
UIWindow *w = d.window;
UIViewController *vc = w.rootViewController;
UITabBarController *c = (UITabBarController *)vc;
UITabBar *t = c.tabBar;
[action showFromTabBar:t];
I would think if you got a reference to the tab bar controller then you should be able to present it from that. You can try showing it from the main window but I would think you shouldn't rely on that.
[action showInView:[[UIApplication sharedApplication] keyWindow]];
Try this:
CGRect r = CGRectMake(x, y, w, h); //change values to fit location of button
[actionSheet showFromRect:r inView:self.view animated:YES];
I used it on one of my apps with the same problem and the dismiss button showed up ok.

How to show a UIView OVER a UIPopoverController

In my app, I have my main view and when i click a button, a UIPopoverController is shown over my main view (not fullscreen so i still see the view behind) containing a UITableView. When I click one of the tableview cells, I want to show a custom view centered on screen (simple view informing the user that the app is processing) that will fade in and fade out during a specific amount of time.
The problem is that my custom view always appears UNDER the UIPopover...I tried all I can think of, bringSubviewToFront etc...Nothing works... I also tried to wrap my custom view in a UIViewController and use [mainView presentViewController:myCustomView ...] but when I do that the main view disappear
Someone can help?
Thx
Thx Ole Begemann, this question was indeed a duplicate.
Although, the solution to my problem is not to subclass UIWindow but to add my UIView to the key UIWindow :
NSArray * windows = [[UIApplication sharedApplication] windows];
UIWindow* win0 = [windows objectAtIndex:0];
[win0 addSubview:loadingView];
[win0 bringSubviewToFront:loadingWindow];

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.

Create UINavigationController programmatically

Just because I am unable to find a secure way (in a sense that it can be rejected by Apple guys) to customize UITabbar, in particular UITabBarItem I am trying some workaround.
I have a main view on which I recreate a kind of UITabBar, a normal view with two buttons inside. This is (roughly) the current hierarchy:
-MainView
--placeholder(UIView)
--fakeTab (UIView)
What I want to do is, after tapping a button in fakeTab, build a UINavigationController and add it to "placeholder" view so that the fakeTab remain on top and the whole navigation happens on the placeholder level.
I already tried with this piece of code in the method that it's intercepting tap button, and it works, I can see the ipvc.view added to placeholder.
IPPlantsViewController *ipvc = [[IPPlantsViewController alloc] initWithNibName:#"IPPlantsView" bundle:[NSBundle mainBundle]];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:ipvc];
UIView *placeholder = [self.view viewWithTag:200];
[placeholder addSubview:ipvc.view];
But later when I call from inside ipvc, then nothing happens:
IPAttributes *ipas = [[IPFactory findPlantByIndex:indexPath.row] attrs];
[self.navigationController pushViewController:ipa animated:YES];
I find the solution myself. What I was doing wrong is to attach the ipvc controller view to placeholder. Instead of doing this:
[placeholder addSubview:nav.view];
and everything works as expected, with my fake tabbar fully customized :-)
But, as a side note, the viewWillAppear seems to be never called.
It would be interesting to know why. I partially solved by making IPPlantsViewController the delegate of the UINavigationController.