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 !
Related
I am trying to present a modal view from one of my view. The presenter view is already shown as a modal from a custom view. My problem is that I am not able to see the 'Done' button on the new Modal view presented. Below is my code. Am I missing something?
UIViewController *aViewController = [[UIViewController alloc] init];
UINavigationController *aNavigationController = [[[UINavigationController alloc] initWithRootViewController:aViewController] autorelease];
[aNavigationController.navigationBar setBarStyle:UIBarStyleBlack];
UIBarButtonItem *aBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(dismissMe)];
[aNavigationController.navigationItem setLeftBarButtonItem:aBarButtonItem];
MyView *aView = [[MyView alloc] initWithFrame:self.view.frame];
[aViewController.view addSubview:aView];
[self presentModalViewController:aNavigationController animated:YES];
[aViewController release];
- (void)dismissMe {
[self dismissModalViewControllerAnimated:YES];
}
If I understand weel the question, you can try a solution like this:
Write this in the viewDidLoad or init method of the modal view controller you want to show from the actual view:
UIBarButtonItem *done = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self selector:#selector(dismissMe)];
self.navigationController.leftBarButtonItem = done;
and implement you dismissMe method.
Instead, in the presenter controller write this where you want to present the new modal controller:
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controllerYouWantToShow];
[self presentModalViewController:navController animated:YES];
Obviusly, controllerYouWantToShow is a pointer/variable pointing your view controller you want to show... I usually do this to solve a problem like yours... However, check the code because I havent't tested it :)
Hope it helps!
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.
I want to show the subview of a view in popover.
To elaborate,
I have a mainViewController.
I hava a subview 'songListView' in this mainViewController.
I have a button titled 'list' in the mainViewController' itself.
I want to show the songListView in popover on clicking the button 'list'.
So, how should I do this.
You could use the below code as a reference for showing PopOver from a UIButton
-(void) buttonAction:(id)sender {
//build our custom popover view
UIViewController* popoverContent = [[UIViewController alloc]
init];
UIView* popoverView = [[UIView alloc]
initWithFrame:CGRectMake(0, 0, 200, 300)];
popoverView.backgroundColor = [UIColor greenColor];
popoverContent.view = popoverView;
//resize the popover view shown
//in the current view to the view's size
popoverContent.contentSizeForViewInPopover =
CGSizeMake(200, 300);
//create a popover controller
self.popoverController = [[UIPopoverController alloc]
initWithContentViewController:popoverContent];
//present the popover view non-modal with a
//refrence to the button pressed within the current view
[self.popoverController presentPopoverFromRect:popoverButton.frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
//release the popover content
[popoverView release];
[popoverContent release];
}
My problem is solved.
I just created another View Controller class, i.e. 'TempPopoverView'.
Then I set the view of this TempPopoverView equal to the subview of my MainView
Here is the code snippet from my code:
TempPopoverView *viewController = [[TempPopoverView alloc]initWithNibName:#"TempPopoverView" bundle:nil];
[self. songListView setHidden:NO];//songListView is subview of MainView
viewController.view=self. songListView;
UINavigationController *navCont = [[UINavigationController alloc]initWithRootViewController:viewController];
navCont.navigationBar.tintColor = [UIColor colorWithRed:.102 green:.102 blue:.102 alpha:1];
[self showPopOverController:navCont andFrame:sender.frame andInView:self.view];//self.view is the MainView
[viewController release];
[navCont release];
U can use presentModalViewController on your main view.
For example
SongListView *songList = [[SongListView alloc] init];
[self presentModalViewController: songList animated: YES];
There are different animations possible as well.
as simple as you think to add subview in self.view
[popoverController.contentViewController.view addSubview:yourselfobject];
Check this, im pushing a modal view inside of another modal view. But, im trying to put a button inside of this modal view, but without luck.
What im doing wrong?
Thanks!
CadastroViewController *addController = [[CadastroViewController alloc] initWithNibName:#"CadastroViewController" bundle:nil];
// This is where you wrap the view up nicely in a navigation controller
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addController];
// You can even set the style of stuff before you show it
navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
navigationController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"OK" style:UIBarButtonItemStyleBordered target:self action:#selector(buy)];
// And now you want to present the view in a modal fashion all nice and animated
[self presentModalViewController:navigationController animated:YES];
// make sure you release your stuff
[navigationController release];
[addController release];
You'll have to add a new UINavigationItem to the navigationbar of the actual viewcontroller - NOT the navigation controller.
addController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"OK" style:UIBarButtonItemStyleBordered target:self action:#selector(buy)];
You should add your button in a
-(void) viewDidLoad of your CadastroViewController controller class
This will look like this:
- (void) viewDidLoad
{
[super viewDidLoad];
UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithTitle:#"OK" style:UIBarButtonItemStyleBordered target:self action:#selector(buy)];
self.navigationController. leftBarButtonItem = button;
[button release];
}
[self presentModalViewController: navigationController animated:YES]; is ok in your example, just all other initializations you should do in viewDidLoad
It seems to me, that the problem is here:
[self presentModalViewController: navigationController animated:YES];
Instead try do this:
[self presentModalViewController: addController animated:YES];
In my app I have a basic Navigation Controller. For all of my views, except one, the controller works as it should.
However, for one view in particular, I would like the 'back' button to not go back to the previous view, but to go to one I set. In particular it is going to go back 2 views and skip over one.
After doing some research I found that I can intercept the view when it disappears, so I tried to put in code to have it navigate to the page I would like:
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
//i set a flag to know that the back button was pressed
if (viewPushed) {
viewPushed = NO;
} else {
// Here, you know that back button was pressed
mainMenu *mainViewController = [[mainMenu alloc] initWithNibName:#"mainMenu" bundle:nil];
[self.navigationController pushViewController:mainViewController animated:YES];
[mainViewController release];
}
}
That didn't work, so does anyone have any ideas?
Thanks!!
In your code, you seem to be trying to push another view controller onto the stack, rather than pop an extra item off it.
Try this as your code that does the going back two levels:
NSArray *vcs = [self.navigationController viewControllers];
[self.navigationController popToViewController:[vcs objectAtIndex:[vcs count]-3];
Alternatively you could totally replace the back button with a button of your own? In your viewController:
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonItemStyleBordered target:self action:#selector(doSomething:)];
self.navigationItem.hidesBackButton = YES;
self.navigationItem.leftBarButtonItem = item;
[item release];
Then you can write the doSomething: method to pop the two items off the stack, perhaps using the code I posted above.
Simple solution:
- (void)viewWillDisappear:(BOOL)animated {
//if true, back was pressed
if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) {
//your logic
}
}
You can try implementing the UINavigationBarDelegate delegate. When the method -navigationBar:didPopItem: is called, you can pop an additional item from the UINavigationController, and thus pop two items at once.
UIButton *home = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *homeImage = [UIImage imageNamed:#"back.png"];
[home setBackgroundImage:homeImage forState:UIControlStateNormal];
[home addTarget:self action:#selector(LogOut)
forControlEvents:UIControlEventTouchUpInside];
home.frame = CGRectMake(0, 0, 69, 26);
UIBarButtonItem *button2 = [[UIBarButtonItem alloc] initWithCustomView:home];
[[self navigationItem] setLeftBarButtonItem:button2];
[button2 release];
button2 = nil;