I am writing an iPad app that requires the user to enter names and addresses and would like to use ABNewPersonViewController as the interface. The documentation says that this view controller should only be used from within a navigation controller. Is there anyway I can use just the ABNewPersonViewController in a subview (with a navigation controller) without it taking over my whole screen? I assume I can do this easily enough in a popover but I would prefer to have it integrated into my interface... Thanks for any help you can provide!
Consider presenting your UINavigationViewController by presentModalViewController:animated: and change modalViewPresentationStyle to UIModalPresentationPageSheet.
See the reference : http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html
Well, after much looking into this, it does not see that there is any way to use the address book UIs in a subview but they do work quite well in a popover view. However, this popover needs to be exactly 320x460 pixels or some other number with the same aspect ratio for the "add photo" to work correctly (otherwise the photo is stretched). In the popover's view controller viewDidLoad method I added:
self.picker = [[[ABNewPersonViewController alloc] init] autorelease];
self.picker.newPersonViewDelegate = self;
self.navigationController = [[[UINavigationController alloc] initWithRootViewController:self.picker] autorelease];
self.navigationController.view.frame = CGRectMake(0.0, 0.0, self.view.frame.size.width, self.view.frame.size.height);
[self.view addSubview:self.navigationController.view];
This seems to work fine. Let me know if you know of something better.
Related
Does anyone know of a way to load a view controller at a point other than the top. This would be similar to opening a web page part way down ie Go to Target
This is not a tableview or webview so the point is not to go to a specific row of the table or place in the webview. Rather it is a regular UIVIewController and the point is to go to a specific vertical point on the screen where there is some relevant content.
Thanks for any suggestions.
Edit: I ended up using the following, not as elegant as I was hoping, but adequate:
-(void) raiseView:(float) float {
CGRect contextRect = self.view.bounds;
float boundsY = contextRect.origin.y;
contextRect.origin.y=boundsY+float;
self.view.bounds = contextRect;
}
I recommend reading up further on controller based interface and how to best use the common practices to your advantage.
My suggestion would be to rely on the presentation styles available to aUIViewController. Here would be an example of presenting a view controller over the current view:
MyViewController *controller = [[MyViewController alloc] init];
controller.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[currentViewController presentViewController:controller animated:YES completion:^{
// Do whatever you need to here
}];
Then upon completion, you can do anything you need to for presenting your content. Here you can simply set the controllers view to be whatever frame you desire (with, in your terms, any top point you would like). This way you can present a VC to the user and display anything you need on top at the point relevant to the content on the previous view.
Happy coding!
I have designed two ViewControllers - VCLarge and VCSmall. VCSmall is freeform.
When I display VCSmall on top of VCLarge - I shows full screen.
So I play tricks and change the formSize in ViewWillAppear - The VCLarge still does show (I see black)
FYI - I do this when the ViewControllers are in a storyboard and have no problem.
IF you want to present your viewcontroller like UIPopover controller like below...
Please see this OpenSource FPPopver.
It is perfect and works fine.
Very easy to implement.
https://github.com/50pixels/FPPopover
YourViewController *controller = [[YourViewController alloc] init];
//our popover
FPPopoverController *popover = [[FPPopoverController alloc] initWithViewController:controller];
[popover presentPopoverFromView:okButton];
That's all.
If you want to get rid off that ARROW tip, you can do that too!
you use [UIView addSubview] to show it on top of VCLarge.
For example, if you're within VCLarge, you would do something like this:
UIView *smallView = [VCSmall alloc] init...
[self.view addSubview:smallView];
You can adjust the size and or position of smallView using appropriate CGRects for smallView.
I have a third party control that wants me to put a view inside of it. I'm trying to get a UINavigationController containing a series of table views inside of it, but when adding the controls the navigation bar overlaps the tableview by about half a row, which looks dumb.
Here's the code. I'm using the ArcGIS Server iOS SDK to put the navigation controller in a callout box on the map:
IdentifyResultsViewController *idWindow = [[IdentifyResultsViewController alloc] init];
idWindow.results = results;
UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:idWindow];
map.callout.customView = nvc.view;
nvc.view.frame = CGRectMake(0, 0, 275, 400);
[map showCalloutAtPoint:self.mapPoint];
Is this a common problem using the UINavigationViewController, or should I look to the third party control?
I actually just had a similar problem with a third party control obstructing my navigation bar. I tried to look into the control but I'm not versed enough to unhide the navigation bar.
What I did may be something you can do too: instead of using the built in UINavigationBar, I kind of built one myself by just putting in a UIView at the top of the page and adding custom buttons to it that performed the functions that I wanted in the bar. This gives you a little more wiggle room around that third party control if you can't find what's causing the issue.
Hope it helps!
I solved this using some simple reordering of code - instead of using initWithRootViewController, I created the navigation view controller, set it's frame manually, and then pushed the view controller on to it:
IdentifyResultsViewController *idWindow = [[IdentifyResultsViewController alloc] init];
idWindow.results = [self filterResults:results];
UINavigationController *nvc = [[UINavigationController alloc] init];
nvc.view.frame = CGRectMake(0, 0, 275, 400);
[nvc pushViewController:idWindow animated:NO];
map.callout.customView = nvc.view;
[map showCalloutAtPoint:self.mapPoint];
I have a UIPopoverController with two view controllers inside of it. I'm building it like so:
CommentsPopoverController *commentsPopoverController = [[CommentsPopoverController alloc] init];
self.delegate = commentsPopoverController;
commentsPopoverController.navigationItem.title = #"Comments";
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:commentsPopoverController];
popover = [[UIPopoverController alloc] initWithContentViewController:navController];
Inside my commentsPopoverController I have this:
commentsViewController = [[CommentsViewController alloc] init];
commentsViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
addCommentsViewController = [[AddCommentViewController alloc] init];
addCommentsViewController.view.frame = CGRectMake(0, commentsViewController.view.bounds.size.height - 200, 320, 346);
addCommentsViewController.view.backgroundColor = [UIColor darkGrayColor];
[self.view addSubview:addCommentsViewController.view];
[self.view addSubview:commentsViewController.view];
So when I first load the popover, the addCommentsViewController is hidden by the commentsViewController. When I reveal it, it looks like this:
So far so good. The problem I'm having is that from here, when the user rotates the device or shows the keyboard or shows the keyboard THEN rotates the device things start to get out of whack. The top view controller (commentsViewController) which is a UITableView always does the right thing no matter what the orientation is or whether or not the keyboard is showing. But the bottom view controller (addCommentsViewController) doesn't automatically change it's origin.y to stay directly under the top view controller.
So I've basically had to hack the crap out of my code to keep the addCommentsViewController directly under the commentsViewController by constantly calculating the height of the top view controller so that I could adjust the bottom view controller's origin.y. This involved dropping in NSNotifications for the keyboard's show/hide state and for the device's orientation and constantly recalculating. Very hackish and ugly.
So my question (finally) is: Is there an easier way of controlling these views or am I stuck hacking it the way I did?
To handle rotation, there are two appropriate techniques. One is that you make CommentsPopoverController's view a subclass of UIView that overrides layoutSubviews to lay out your two views properly. The other is that you define viewDidLayoutSubviews on CommentsPopoverController to lay out your views. If you lay out your views in either of these methods, you shouldn't have to subscribe to rotation notifications.
As for moving your view out from under the keyboard, that is discussed in the Text, Web, and Editing Programming Guide for iOS. Part of the technique involves subscribing to keyboard will show/did hide notifications.
I assume your CommentsViewController is a subclass of UITableViewController, because UITableViewController takes care of adjusting the table view when the keyboard is hidden or shown.
I just started learning developing an application (primarily) for iPad using MonoTouch. Maybe because of my many years experience in C# world, it makes my switch very difficult, and I feel stupid sometimes. This is very simple thing in C#, but it make me scratch my head...
Popup dialog?
For iPhone, you rarely have this requirement, because whatever you show will occupy the whole screen, so you just create a controller for each popup.
For iPad, I have much more space, and I don't want the whole screen to be occupied with a few controls (e.g. login screen). That's why I want to show it as a popup. I have seen this in other iPad apps.
From what I learned, I need to use UIAlertView or UIActionSheet to do this. But what I don't understand is that, as shown by all the examples I have read, you have to create all the controls from the code.
What I would like to do is to create the UI using IB, and plug it into UIActionSheet. Is it possible? How do I do it?
If this is an iPad-only application, you will want to use a UIPopoverController. This is a popup "window" that contains a view and is linked to an area on the screen, such as a toolbar button or a rectangle (such as the Frame of a UIButton).
To use this, create a new instance of UIPopoverController, using the constructor that accepts a UIViewController and pass the view that you want to show.
Due to garbage collection considerations, make sure that you store the UIPopoverController in a class-level property.
You will probably also want to clean up this property when the popover is closed. To support this, we subclassed the UIPopoverController, added an event that can be hooked by the caller, then overrode the Dismiss method and fire the hooked event, if any, in the overridden method.
Once you instantiate the popover, you will want to show it. You can do this through one of the PresentFromxxx methods. If you are presenting this from a button (not toolbar) you can call PresentFromRect using the button's frame as the rectangle.
The view that is presented can control its size by setting the ContentSizeForViewInPopover property in its ViewDidLoad method.
You can't edit a UIActionSheet or UIAlertView from Interface Builder.
What you can do is create a view in Interface Builder and display it modally over top of your other views, however it sounds like you don't want to occupy the entire screen and this is what would happen. Here is an example of a modal view controller: http://pastebin.com/h221BQdK
I think you should just follow the examples you mention and create a UIAlertView from code, maybe put it a static utility class. I created a MessageBox class to be more like windows, but you can also put text boxes on there for login. Look at the login box on the app store, it is a decent example of what it would look like.
Create a viewcontroller named extraviewcontroller set its height width to 300 * 215 .
and write the code below
inviewdidload
pickerviewTitle = [[UIPickerView alloc] initWithFrame:CGRectMake(0,0, 383, 250)];
pickerviewTitle.delegate = self;
pickerviewTitle.tag = 0;
pickerviewTitle.showsSelectionIndicator = YES;
controller = [self.storyboard instantiateViewControllerWithIdentifier:#"ExtraViewController"];
popovercontroller = [[UIPopoverController alloc] initWithContentViewController:controller];
popovercontroller.delegate = self;
then
UIActionSheet *actionSheet1 = [[UIActionSheet alloc] initWithTitle:#"Title" delegate:self cancelButtonTitle:#"Done" destructiveButtonTitle:nil otherButtonTitles:nil];
actionSheet1.tag = 0;
actionSheet1.actionSheetStyle = UIActionSheetStyleDefault;
[actionSheet1 addSubview:pickerviewTitle];
[actionSheet1 setFrame:CGRectMake(0, 0, 600, 400)];
[controller.view addSubview:actionSheet1];
if ([popovercontroller isPopoverVisible]) {
[popovercontroller dismissPopoverAnimated:YES];
} else {
//the rectangle here is the frame of the object that presents the popover,
//in this case, the UIButton…
CGRect convertedFrame = yourclickbutton.frame;
[popovercontroller presentPopoverFromRect:convertedFrame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionRight
animated:YES];
}