Dismiss popover from the button on popup - ios

I have created a popover, containing a table
when user will select the row at that time I want to dismiss popover.
any Idea.

Have a look in the apple documentation... Have a look at the popoverclass...

When your table delegate method gets called, close the popover:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[popoverController dismissPopoverAnimated:YES];
// Handle the row click
}
Where popoverController is an instance variable set up when you created the popover.

Related

How to connect two view controller to one view controller using Storyboard?

I'm trying to connect two view controller into a one controller. As you can see below picture, when "plus" item is tapped the screen came and it works well. However, the other segue doesn't work properly. With my first tapping to any row, it doesn't take me to the view but after first tapping it starts taking me to the view as I wanted. I couldn't figure out why it doesn't take me to when I firstly tap any row. Here is the didSelectRowAtIndexPath code:
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
DovizDetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:#"detail"];
[self.navigationController pushViewController:detail animated:YES];
}
Below is my storyboard. The problem is about with the above view and it's segue.
Hope you can help me.
Thanks!
Change didDeselectRowAtIndexPath to didSelectRowAtIndexPath

Dismiss navigation controller and all of its view controllers stack in UIPopupview using a button within one of the views

I am displaying a UIPopoverView using the code:
selectClientPopController= [[UIPopoverController alloc]initWithContentViewController: [self.storyboard instantiateViewControllerWithIdentifier:#"navControllerMini"]];
selectClientPopController.popoverContentSize=CGSizeMake(500, 700);
selectClientPopController.delegate=self;
[selectClientPopController presentPopoverFromRect:CGRectMake(cell.frame.origin.x+120-scrollView.contentOffset.x, cell.frame.origin.y+120,cell.frame.size.width, cell.frame.size.height) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft | UIPopoverArrowDirectionRight animated:YES];
This navigation view controller is ued to step through a two TableViewControllers as shown below:
When a cell on the last tableView is pressed, I would like to dismiss the whole popover.
I understand that this probably needs to be done using delegates, however I do not know where to assign the delegates in order to achieve this. Thanks for the help.
Why Not
// Listen for TableView row selection by setting up delegate.
// Basically self if you set the delegate in the same view controller
YourTableView.delegate = YourViewControllerObjectWhichHasTableView;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[selectClientPopController dismissPopoverAnimated:YES];
}
Whenever u need to dismiss the popover just use the above method. Refer the Apple's Documentation

How can I push a new view when detail button is presses

I have a tableView. My tableView cells do have a detail accessory.
My question: How can I push another view controller when the detail button is presses.
When I normally press the cell, my ViewController1 opens. But when I tap on the little i on the right of the cell, I want to push a different view controller.
How can I do this?
it is just like DidSelectRow u need to modify DidSelectRow to accessoryButtonTappedForRowWithIndexPath
-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
// if u using .Xib
yourviewcontrollerName *vie=[[yourviewcontrollerName alloc]init];
[self.navigationController pushViewController: vie animated:YES];
//// if u using storyboard
[self performSegueWithIdentifier:#"yoursequeName"
sender:self];
}
you need more information use this link Pushing to a Detail View from a Table View Cell using Xcode Storyboard
Use this code it works
-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
// Push new View controller here
UIViewController *objVc=[[UIViewController alloc]init];
[self.navigationController pushViewController:objVc animated:YES]
}

Modal UITableView Won't recognize first click

I have a UITableViewController that I display modally. When the user clicks on any cell, I need to capture that choice and dismiss the view controller. The weird thing is that the first cell that is clicked is not recognized. When the user clicks on another cell, that is recognized and everything works as intended. Obviously, I need the first click to be the one that is recognized. What am i doing wrong?
- (void) tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(#"cell clicked");
// capture user selection and return to previous screen
[self dismissViewControllerAnimated:YES completion:nil];
}
You are using tableView:didDeselectRowAtIndexPath: instead of tableview:didSelectRowAtIndexPath: ;)

deselectRowAtIndexPath issue

I have just started working with tableViews, and I have 5 cells in a tableview in a viewController embedded in a navigationController. When a cell is pressed another view is pushed in. My problem is that the cell I press is selected but the selection doesn't go away. I have tried with this code:
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.tableView deselectRowAtIndexPath:indexPath animated:NO];
NewViewController *newViewController = [[NewViewController alloc] init];
newViewController.theTitle = [self.tableView cellForRowAtIndexPath:indexPath].textLabel.text;
[self.navigationController pushViewController: newViewController animated:YES];
}
The tableView is initialized in the viewDidLoad method. Still when I click a cell the new viewController is pushed in but the cell stays selected. What might be the issue here?
You've put your code in the didDeselectRowAtIndexPath - put it in the didSelectRowAtIndexPath. This is an easy mistake to make since didDeselect comes up in code completion before didSelect.
Summary :
You have tableview that is in a ViewController that is in a NavigationController
Use touch a cell
A new ViewController is push on the NavigationController Stack
User hit back and goes back to the screen where you have a tableView
That is what I understand from your question.
At this moment the cell in your tableView should still be selected in order for the user to have a reminder of the last action he as done, but you also want it to get unselected animated at the point ( the mail application is a good example of this behaviour).
So the best place to deselect the cell in your tableView is in - (void)viewDidAppear:(BOOL)animated method of the UIViewController that have the tableview inside it's view. By doing so you will let the user a chance to see the selection before it gently fade away like in mail.
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:animated];
}
You can pass nil as argument of deselectRowAtIndexPath, tableView handles it gracefully.
Did you also implement tableView:didSelectRowAtIndexPath:? This method is called every time you tap a cell. So you should put your code there.
The method you are using, tableView:didDeselectRowAtIndexPath: is called whenever a cell is selected and you are tapping a different cell.
I think your problem is that you use wrong method. Change didDeselectRowAtIndexPath to didSelectRowAtIndexPath.

Resources