The context:
I am working on an app that maintains a list of contacts along with their record IDs for it's own reference.
When the user needs to change the number associated with a specific contact within the app, I am trying to display the ABPersonViewController so the user can choose the new number from the contact in AB.
The problem:
The problem is that the ABPersonViewController that is opened is starting all the way from the top of the screen as if it does not know that there is a navigation bar on the top.
As a result some of the top part of the ABPersonViewController screen (the top part of the person image and the top part of the name) is underneath the navigation bar.
Ideally i want it to look like this, but not in edit mode: http://developer.apple.com/library/ios/documentation/ContactData/Conceptual/AddressBookProgrammingGuideforiPhone/Art/person_view.jpg
Also I wanted to add a "cancel" button to the top right part of the nav bar. Trying to add that as a bar button is not working either.
The code:
this is how I am adding the ABPersonViewController to the navigationController:
ABPersonViewController *personViewController = [[ABPersonViewController alloc] init];
personViewController.personViewDelegate = self;
personViewController.displayedPerson = person;
[self.m_circleNavController pushViewController:personViewController animated:YES];
[personViewController release];
The self here is a UIVIewController.
The m_circleNavController is the UINavigationController to which the UIVIewController belongs.
I tried these 2 ways of showing the person view, but both behave the same way.
[self.m_circleNavController pushViewController:personViewController animated:YES];
[self.navigationController pushViewController:personViewController animated:YES];
I'm not too sure what I am doing wrong, or what is the best way to do it.
I tried a lot of different ways to display it in vain.
The viewcontroller was behaving as though it was starting about 40 pixels above the top edge of the screen.
I was able to fix it in a very weird way finally. In the init function of the viewcontroller I added the following line:
self.view.bounds = CGRectMake(0, -43, 320, 440);
But still no clue as to why it happens this way. I was to close to the deadline to look for a decent solution.
Hello I've been having the same problem as of the new iOS. When this happens on my custom view controllers I have been able to correct it with:
if (self.interfaceOrientation != UIInterfaceOrientationPortrait) { // UI is in landscape position
[self.tableView setContentInset:UIEdgeInsetsMake(32,0,0,0)];
} else { // UI is in portrait position
[self.tableView setContentInset:UIEdgeInsetsMake(44,0,0,0)];
}
But when using the ABPersonViewController I don't quite know how to handle this problem.
Hope someone has an idea...
Related
I have a Box2D world which works great. I'm using it in a simple iOS game where the user tilts the device to push bodies around the screen racking up points when a certain body collides with another.
It was working fine when it was buried a couple layers deep in my app in a test controller. I invoked it from a button on my menu screen and a button on the game screen would return to the menu just fine via popToViewController. But once I saw how great it worked I realized that I wanted the game to be the first screen a user sees (after the default loading image). So now the app loads the world and the game is on right off the bat without any problems.
Until the user taps the menu button to get to the menu screen - another view controller. The menu controller loads fine and everything works there as expected. BUT when one taps the back button to return to the game/world the images/bodies are distorted. The distortion varies depending on how they happened to be rotated when the menu controller got pushed onto the navigation stack. Sometimes they are enlarged and sometimes smooshed.
I did try pausing the world (by not calling Step) when loading the menu controller, but that did not help with the image distortion problem.
Here is the code where the menu controller gets loaded:
//unhide the navbar for the next screen
[self.navigationController setNavigationBarHidden:NO];
MenuViewController *mvc = [[MenuViewController alloc]init];
[self.navigationController pushViewController:mvc animated:YES];
[mvc release];
And here is where the game's view controller gets loaded by the app delegate in application didFinishLaunchingWithOptions:
B2DViewController *b2dvc = [[B2DViewController alloc]init];
UINavigationController *navcon = [[UINavigationController alloc] init];
[navcon setNavigationBarHidden:YES];
[navcon pushViewController:b2dvc animated:NO];
[window addSubview:navcon.view];
[b2dvc release];
[window makeKeyAndVisible];
The images come in via a xib. One is button and one is an imageView. Both are added to dynamic bodies which are configured thusly:
b2PolygonShape dynamicBox;
dynamicBox.SetAsBox(boxDimensions.x, boxDimensions.y);
...
b2FixtureDef fixtureDef;
fixtureDef.shape = &dynamicBox;
fixtureDef.density = 3.0f;
fixtureDef.friction = 0.3f;
fixtureDef.restitution = 0.5f;
...
I tried hiding all the subviews but, as you might suspect, that only hid them from view, not from the forces of distortion. I also turned off all the stretching and resizing stuff in IB, to no avail (I was just guessing).
I'd be grateful for any assistance or ideas that anyone might have.
Instead of pushing the menu controller onto the navigation controller and then adding the navigation controller to the view I instead used presentModalViewController: animated. This didn't fix the problem, but once I commented out [self.navigationController setNavigationBarHidden:NO]; the problem was resolved.
//unhide the navbar for the next screen
//[self.navigationController setNavigationBarHidden:NO];
MenuViewController *mvc = [[MenuViewController alloc]init];
[self presentModalViewController:(UIViewController *)mvc animated:YES];
[mvc release];
It seems that the NavigationBar was smashing the images? I'd like to look into this further as the navigation bar can be a handy thing, but I don't have time now, which probably means I'll never get around to it.
I want a photo viewer in my iphone app and I liked the Three20 photo viewer. I found it somehow hard to integrate it in my own app where I have my typical UINavigationViewController. So far I succeeded in doing the following:
TTURLMap *map = [[[TTURLMap alloc] init] autorelease];
[map from:#"tt://appPhotos" toSharedViewController:[PhotoViewController class]];
[self.navigationController pushViewController:[map objectForURL:#"tt://appPhotos"] animated:YES];
The only problem is that wenn I click back to my original view, its navigation bar keeps the style of the photo viewer (transperant and shows the view under it).
How can I get back my original navigation bar?
My experience: I once used three20's PhotoViewer and every time I went back from the PhotoViewer to my other view. The system status bar remained black and transparent (while it should be with default style). I solved it by manually and programmatically changing the status bar style every time when the back action was triggered.
Yes, this is a bit of an issue for sure. A good solution, as #diwup says, is to implement a manual fix. I tend to subclass TTPhotoViewer when I need it. Not only does it help with this problem but it also makes it much easier to use I find.
If you decide to subclass, then you should use whatever variation of the following you require:
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
self.navigationController.navigationBar.tintColor = myTintColor;
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
}
However, if you don't want to subclass, you can always put the code into the - [viewWillAppear:] method of any class that comes after the photo viewer.
Just when i thought I had everything figured out .. i got this problem.
the scenario.
I got a simple tableView. and with a search bar in navigation item's titleView. The SearchBar is added to navItems titleView via a uibarbuttonitem in view controllers toolbar.
NOW, normally
After initiating the searchbar with [beginResponder] the keyboard shows up. And It sends out a notification "KeyboardDidShow" which is where i calculate the UIKeyboard's height and set the tableView's height accordingly (Shorten it).
ON Rotation - to and fro landscape/portrait, everything works fine.
-(void)didRotateInferfaceOrientation is called and everythings kool.
Heres the problem.
When the keyboard is active, it has a Google "search" button, this pushes to a new view - webviewcontroller.
the problem is, this
When, [PORTRAIT]ViewController [SearchBar with keyboard active] --> taps Search --> [Portrait]WebViewController --> Change Device Orientation to [Landscape] --> [Landscape]WebViewController changes to landscape ---> HERES THE PROBLEM, user taps back to uiViewController[Landscape]
the method -didRotatefromInterfaceOrientation isnt called. and somehow the tableView height is messed up. Though the view is rotating perfectly.
Is there something im missing here..
would appreciate any help. .thanks
When user taps back, -didRotatefromInterfaceOrientation will not be called. You need to check orientation in viewWillAppear (or call viewDidLoad, prior to returning from tap on back), and then call the proper layout for the chosen orientation.
In all of your (BOOL)shouldRotate... methods, you should be call a separate method to ensure your layout is correct for the device orientation.
I got a similar problem in one of my applications recently, not exactly our problem but don't bother, you should see what I'm heading for: I wanted to simply rotate an viewController displayed using presentModalViewController...Unfortunatly it didn't really worked put, especially on old iPhone with OS prior to iOS 4...So I needed to rotate programatically! Just get your screen size, use CGAffineTransform or something like that and change the sizes and then you should be done...
If your interested I could post a bunch of code, so let me know!
EDIT:
UIScreen *screen = [UIScreen mainScreen];
myController.view.bounds = CGRectMake(0, 0, screen.bounds.size.height, screen.bounds.size.width - 20);
if(currentOrientation == UIDeviceOrientationLandscapeRight){
myController.view.transform = CGAffineTransformConcat(myController.view.transform, CGAffineTransformMakeRotation(degreesToRadian(-90)));
}else{
myController.view.transform = CGAffineTransformConcat(myController.view.transform, CGAffineTransformMakeRotation(degreesToRadian(90)));
}
myController.view.center = window.center;
[[UIApplication sharedApplication] setStatusBarOrientation:currentOrientation];
[self.window addSubview:self.tabBarController.view];
[self.window bringSubviewToFront:self.tabBarController.view];
[self.window addSubview:myController.view];
[self.window bringSubviewToFront:myController.view];
[self.tabBarController.view removeFromSuperview];`
This also includes removing a TabBar when rotating to landscape to get some more space...enjoy :)
You could call didRotateFromInterfaceOrientation manually on viewWillAppear and just pass an orientation yourself (i.e. [UIApplication sharedApplication].statusBarOrientation).
i am trying and trying.... but no result yet.
i have a view with a navigationcontroller and -bar. in addition there is a tableview.
if you click on a row, the iphone email function is getting startet by using the email example from apple (MailComposerViewController.h and .m).
it opens and i am able to send or cancel the mail. after that the "dismissModalViewControllerAnimated" methode is dismissing the emailing view. everything looks right, i am in the previous view now, BUT:
when i want to use buttons from the navigationitem or if i want to add rows to the tableview, the app is crashing without any error message.
do i have to set something back or to "remove" something which is still there because of the mailing view?
it's really strange and i am searching now for hours....... :-(
thank you very much in advance!
hopefully someone has an idea.
EDIT:
ok, here i have the code now:
in a tableview which is included in a navcontroller i have following lines to open first a Subclass of UIViewController:
- (IBAction)Action:(id)sender
{
DetailViewController *editViewController = [[DetailViewController alloc] initWithNibName:#"TripDetailViewController" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:editViewController animated:YES];
editViewController.navigationItem.prompt = #"Details";
[editViewController release];
}
in the DetailViewController following action is processed when the user clicks on the button:
- (IBAction)mailTrip:(id)sender {
MailComposerViewController *mailComposer = [[MailComposerViewController alloc] init];
[[[self view] window] addSubview:[mailComposer view]];
[mailComposer showPicker:sender];
}
when i press the related button, the MailComposerViewController pushes up correctly. all functions of the MailComposerViewController are working correct.
but when i send or cancel the mail and the MailComposerViewController disappears, my previous view doesn't work anymore.
in the MailComposerViewController-Example from apple the MailComposerViewController just disappear and the previous view is working fine again.... :-(
ok, i found the stupid simple problem.
the MailComposer-View was after dismissing it still over the previous view.
i did set the propert hidden after dismissing and now it works...
[self dismissModalViewControllerAnimated:YES];
[[self view] setHidden:YES];
but i am really not sure if this is the right way to do it...
I hope someone can help... This issue has been discussed here and I have tried the solutions suggested but to no avail.
My problem is best illustrated using the example project which can be downloaded from this URL:
http://www.hitsalive.com/tmp/VCTest.zip
In the example project I have a main UIViewController with two buttons used to call two other UIViewControllers - one using presentModalViewController and the other using "addSubView" (using the AppDelegate). Individually both buttons and UIViewControllers work fine.
However, if I first call the modal viewcontroller, then dismiss it (using dismissModalViewControllerAnimated: YES) and then display the second (addSubView) UIViewController, then all elements and subviews in the second UIViewController (such as the button in the example) get displaced downwards vertically by 20 pixels. And the displacement happens with a momentary delay.
This issue does not happen with SDK 3.2 and below -- just iOS4.
Any help would be appreciated, especially with reference to the example project above.
add [aViewControllerTwo setWantsFullScreenLayout:YES]; to your - (void)flipToViewControllerTwo after ViewControllerTwo *aViewControllerTwo = [[ViewControllerTwo alloc] initWithNibName:#"ViewControllerTwo" bundle:[NSBundle mainBundle]];
In order to solve this you need to do the following with the view controller that appears shifted: add a frame, then set the position of this frame appropriately. Set this frame to the view of the ViewController.
shiftedViewController* ShiftedViewController = [[ShiftedViewController alloc] init ];
CGRect theFrame = [shiftedViewController.view frame];
theFrame.origin.y = 20;
theFrame.origin.x=0;
[shiftedViewController.view setFrame: theFrame];
[self presentModalViewController:shiftedViewController
animated:YES];