ABUnknownPersonViewController *unknownPersonViewController = [[ABUnknownPersonViewController alloc] init];
unknownPersonViewController.view.frame = CGRectMake(0, 20, 320, 400);
//unknownPersonViewController.displayedPerson = (ABRecordRef)[self buildContactDetails];
unknownPersonViewController.allowsAddingToAddressBook = YES;
UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
cancelBtn.frame = CGRectMake(262, 6, 54,30);
[unknownPersonViewController.view addSubview:cancelBtn];
[self presentModalViewController:unknownPersonViewController animated:YES];
[unknownPersonViewController release];
i am using UIViewcontroller and in this code i want that a bar like navigation bar will show in upper
side of this controller so i want to put cancel button on that bar.any help?
What you should do is embed your ABUnknownPersonViewController in a UINavigationController
UINavigationController *newNavigationController = [[UINavigationController alloc] initWithRootViewController:unknownPersonViewController];
[self presentModalViewController:newNavigationController animated:YES];
[view release];
[newNavigationController release];
That way you wouldn't even have to add the button yourself, the ABUnknownPersonViewController would take care of it for you.
For more info check Address Book Programming
Hmm, the online documentation says "Important Unknown-person view controllers must be used with a navigation controller in order to function properly." So, unlike a lot of the utility view controllers, I don't think you should be invoking
[self presentModalViewController:unknownPersonViewController animated:YES];
But rather
[self.navigationController pushViewController:view animated:YES];
I think if you look at their samples, you'll see they push using the navigation controller.
Related
I have a back button on my answer view controller (a view controller that displays answers) if the user hits the back button I created it switches to a view that has the title of "Back" and just an empty tableview, before switching back to my main view of where all the questions to be answered are displayed. Why is this happening? Its a very brief thing, but definitely noticeable!
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 48)];
navBar.delegate = self;
UINavigationItem *backItem = [[UINavigationItem alloc] initWithTitle:#"Back"];
[navBar pushNavigationItem:backItem animated:NO];
UINavigationItem *topItem = [[UINavigationItem alloc] initWithTitle:#"Question"];
[navBar pushNavigationItem:topItem animated:NO];
topItem.leftBarButtonItem = nil;
[self.view addSubview:navBar];
- (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item
{
ViewController *controller = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:controller animated:YES completion:nil];
return true;
}
- (void)navigationBar:(UINavigationBar *)navigationBar didPopItem:(UINavigationItem *)item
{
ViewController *controller = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:controller animated:YES completion:nil];
}
You're creating your own UINavigationBar and UINavigationItem instances and you probably shouldn't be. The situation you describe is exactly what a UINavigationController is for. When using a UINavigationController it creates the UINavigationBar and each UIViewController that you show on screen (push into the navigation controller) has its own UINavigationItem (with the title taken from the title of the view controller).
The reason you get an empty 'view' titled "Back" is that you're creating it:
UINavigationItem *backItem = [[UINavigationItem alloc] initWithTitle:#"Back"];
[navBar pushNavigationItem:backItem animated:NO];
Dispense with all of this, create a UINavigationController and make your question view controller it's root view controller, then add the navigation controller to the screen. Then when a question is answered, push the answer view controller:
[self.navigationController pushViewController:answerViewController animated:YES];
see the screen shot is clear to understand what I mean
you can see I add a navigationItem in my pop view
I wish I can dismiss the pop view
But it seems only tab the cell under the pop view
The pop view will dismiss,I try to add this method
[self.view removeFromSuperview];
It only remove the table view , the pop view frame is still there ,only without the content view
Any reply will be helpful : )
Thanks
Webber
/******EDIT******/
I use WEPopoverView into my project
And this is the code I create the pop view when I select the table view
if (indexPath.row==2) {
DaysOfWeek *popView = [[DaysOfWeek alloc]init];
UINavigationController *navPopView = [[UINavigationController alloc] initWithRootViewController:popView];
if (self.popoverController) {
[self.popoverController dismissPopoverAnimated:YES];
self.popoverController = nil;
}
else {
self.popoverController = [[[WEPopoverController alloc] initWithContentViewController:navPopView] autorelease];
CGRect frame = [tableView cellForRowAtIndexPath:indexPath].frame;
[self.popoverController presentPopoverFromRect:frame
inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown|UIPopoverArrowDirectionUp
animated:YES];
}
}
/******EDIT2******/
I try to add Done button when I create the pop view
here is the code , But it only appear a navigation , no Done button
DaysOfWeek *popView = [[DaysOfWeek alloc]init];
UINavigationController *navPopView = [[UINavigationController alloc] initWithRootViewController:popView];
navPopView.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(hidePopView)];
While you add the popup view, set tag to that popupView and then, add them as subview,
then use:
for (UIView *tempView in [self.view subviews]) {
if ([tempView tag]==urTag) {
[tempView removeFromSuperview];
}
}
This retrieves all the subviews and then remove only your popupview
I think that simply releasing your self.popoverController will do the dismiss properly, including all the superviews.
You can also have a look at the dealloc method in WEPopoverController to see which views are involved and need to be removed:
[self dismissPopoverAnimated:NO];
[contentViewController release];
[containerViewProperties release];
[passthroughViews release];
Anyway, the only advantage I see is the possibility of calling dismissPopoverAnimated with YES.
Hope this helps.
EDIT:
How can you connect your done button to your controller?
Make your button accessible through a read-only property of DaysOfWeek; then in your controller, when you create DaysOfWeek, do:
DaysOfWeek *popView = [[DaysOfWeek alloc]init];
[propView.doneButton addTarget:self action:#selector(fullyDismissPopover) forControlEvents:UIControlEventTouchUpInside];
In fullyDismissPopover, you call release or call the sequence of functions highlighted above (but release would be better, I think).
DaysOfWeek *popView = [[DaysOfWeek alloc]init];
UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeContactAdd];
[doneButton addTarget:self action:#selector(hidePopView) forControlEvents:UIControlEventTouchUpInside];
popView.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:doneButton] autorelease];
UINavigationController *navPopView = [[UINavigationController alloc] initWithRootViewController:popView];
This also can figure out the problem !
I want to use UIModalPresentationFormSheet in my app. But i'm using navigation controller. So when i writes following code it is not responding me. What should i do ?
[self.navigationController pushViewController:controller animated:YES];
Try something like this:
// assume controller is UIViewController.
controller.modalPresentationStyle = UIModalPresentationFormSheet;
Then
[self.navigationController presentModalViewController:controller animated:YES];
Check with the below sample working code.
MyModalViewController *targetController = [[[MyModalViewController alloc] init] autorelease];
targetController.modalPresentationStyle = UIModalPresentationFormSheet;
targetController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; //transition shouldn't matter
[self presentModalViewController:targetController animated:YES];
targetController.view.superview.frame = CGRectMake(0, 0, 200, 200);//it's important to do this after
presentModalViewController targetController.view.superview.center = self.view.center;
Taken from -->
How to resize a UIModalPresentationFormSheet?
my app is based on tabbar controller
now in my default view i am showing a viewController and lets say it has Button A, when user press A it should load a my tableviewController but nothing is happening??
-(IBAction)promo:(id)sender
{
aRoot= [[tableViewController alloc] initWithNibName:#"tableViewController" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:aRoot animated:YES];
}
but its not loading anything no error even???
/////////// UPDATE
i did this
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
Promo *aPromo = [[Promo alloc] initWithNibName:nil bundle:nil];//button A is deifned on this VC
// then...
aNav = [[UINavigationController alloc] initWithRootViewController:aPromo];
// [pageOne release];
and in promoviewController
-(IBAction)promo:(id)sender
{atab= [[TableViewController alloc] initWithNibName:#"TableViewController" bundle:nil];
//TableViewController *atab1 = [[TableViewController alloc]initWithNibName:#"TableViewController" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:atab animated:YES];
}
You need a navigationController to push a viewController.
you can't add a viewcontroller to a uitabbar if you want to use the navigation controller.
Where you make your tab bar controller you have to do this:
MyFirstTabViewController *pageOne = [[MyFirstTabeViewController alloc] initWithNibName:nil bundle:nil];
// then...
UINavigationController *ncOne = [[UINavigationController alloc] initWithRootViewController:pageOne];
[pageOne release];
then add ncOne to the tab bar instead of the view controller. :) Then your code in the question should work (given that you're properly declaring aRoot in the header).
EDIT
Start again... choose a view based application call it TabBarTest.
Right click on classes and add three new classes. They need to be subclasses of UIViewController or UITableViewController. Lets say they're called RootViewOne RootViewTwo and SecondaryViewController.
Then open TabBarTestViewController.m
Uncomment the viewDidLoad method.
You need to now put this code in that method:
UITabBarController *tbc = [[UITabBarController alloc] init];
NSMutableArray *viewControllers = [NSMutableArray array];
RootViewOne *vc1 = [[RootViewOne alloc] initWithNibName:nil bundle:nil];
UINavigationController *nc1 = [[UINavigationController alloc] initWithRootViewController:vc1];
nc1.view.backgroundColor = [UIColor redColor];
[viewControllers addObject:nc1];
[vc1 release];
RootViewTwo *vc2 = [[RootViewTwo alloc] initWithNibName:nil bundle:nil];
UINavigationController *nc2 = [[UINavigationController alloc] initWithRootViewController:vc2];
nc2.view.backgroundColor = [UIColor blueColor];
[viewControllers addObject:nc2];
[vc2 release];
[tbc setViewControllers:viewControllers animated:YES];
[self presentModalViewController:tbc animated:YES];
Now open RootViewOne.m and in viewDidLoad put this:
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTitle:#"Click to move through stack" forState:UIControlStateNormal];
[button addTarget:self action:#selector(moveToNextView:) forEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
Now you're going to need a custom method:
-(void)moveToNextView:(id)selector {
SecondaryViewController *page = [[SecondaryViewController alloc] initWithNibName:nil bundle:nil];
page.title = #"Next Page";
page.view.backgroundColor = [UIColor greenColor];
[self.navigationController pushViewController:page animated:YES];
[page release];
}
This is only basic, but you should get an understanding of the kinad process you need to go through. I typed this straight into the browser so there may be spelling mistakes... watch out if you get any errors or warnings. Hopefully this can help you with your project.
Finally i solved this , i changed that VC to Navigation view Controller and then i can push the new view based on button tap,, thanks to thomas also who helped me a lot but i couldn't figure it out.
A view is presented modally:
[self presentModalViewController:modalNavController animated:YES];
This view uses a UITabBarController with 4 elements. One of these elements, "Info" has a button that's only visible if its available. If the button is clicked, it needs to push to another view controller, but I'd also like to maintain the tab bar from it's parent view. I haven't been able to figure out how to do this with or without keeping the tab bar. Ive tried pushing and presentingModally in all the places that I could image. How should this be done properly?
Creating tab bar:
infoController.title = #"Info";
streetViewController.title = #"Street View";
reviewController.title = #"Reviews";
streetViewController.tabBarItem.image = [UIImage imageNamed:#"flag.png"];
infoController.tabBarItem.image = [UIImage imageNamed:#"openMarker.png"];
reviewController.tabBarItem.image = [UIImage imageNamed:#"reviews.png"];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.view.frame = CGRectMake(0, 0, 320, 460);
UINavigationController *infoNC = [[[UINavigationController alloc] initWithRootViewController:infoController] autorelease];
infoNC.navigationBarHidden = YES;
[tabBarController setViewControllers:
[NSArray arrayWithObjects:infoNC, streetViewController, reviewController, nil]];
[self.view addSubview:tabBarController.view];
When you add the view controllers to the tab bar controller you need to do this:
MyCustomViewController *vc1 = [[MyCustomViewController alloc] initWithNibName:nil bundles:nil];
UINavigationController *nc1 = [[[UINavigationController alloc] initWithRootViewController:recipesRootView] autorelease];
[vc1 release];
then add nc1 instead of your custom view.
Then in MyCustomViewController to push another view controller do:
[self.navigationController pushViewController:(UIViewController *)page animated:YES];
That should work for you, and keep the tab bar controller.