UISearchDisplayController doesn't fire didSelectRowAtIndexPath - ios

I have a UIViewController with a UISearchDisplayController in it. I have it showing the search results tableview, but clicking any cells never fires didSelectRowAtIndexPath:
#pragma mark - UITableViewDelegate
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(#"did select row");
}
I've seen these relevant questions:
Why won't my UISearchDisplayController fire the didSelectRowAtIndexPath method?
didSelectRowAtIndexPath does not work when uitableview datasource is filtered
but I'm not making the same mistake. The view controller implements UITableViewDelegate and UISearchDisplayDelegate. The UISearchDisplayController delegate and searchResultDelegate are hooked up to the view controller in the storyboard. But just to be sure I did the following in viewDidLoad:
self.searchDisplayController.searchResultsDelegate = self;
self.searchDisplayController.delegate = self;
I've even tried:
self.searchDisplayController.searchResultsTableView.delegate = self;
The searchResultsTableView is the only UITableView in this view controller.

The code you show in your question is didDeselect, not didSelect. So, if that's what you actually have in your code, that's the problem.

Related

How to open a new view on click of Table View Cell?

I am developing an iOS app which has a TableView, and I want to do sth that when a cell of the TableView is tapped, a new view opens (and then it can get back to the Table View.) I tried some things like working with segues and new view controllers, but it didn't work.
Implement the UITableViewDelegate Protocol :
#interface ViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
For this Protocol the delegate method is below:
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//Create Object for next view controller
NextViewController *vc=[storyboard instantiateViewControllerWithIdentifier:"NextViewController"];
[self.navigationController pushViewController:vc animated:YES];
}
}
Implement the UITableViewDelegate protocol, and implement the method
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
Inside that method you can create your new view.

May I add a table view in a view controller?

I have 2 controllers.
I want to add a table view in the view controller,
and the table view's cell has the custom class of tableviewcell.
I tried to use [self addsubview:(the controller.view) into the controller.
I can see the list, but cannot set each cell's value.
In my viewcontroller:
TableViewController *viewController = [[TableViewController alloc] init];
[self addChildViewController:viewController];
[self.view addSubview:viewController.view];
[viewController didMoveToParentViewController:self];
I try to init the tableviewcontroller in my viewcontroller. Now i can see the tableview. But i cannot set the value of each cell. even more the break point cannot stop in the
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
You will also need to provide a delegate and a data source for your table view, and implement the required methods. I have a strong suspicion you skipped a couple crucial steps here. cellForRowAtIndexPath will never get called unless your view controller is properly set up as the UITableView's delegate and data source.
See the UITableView programming guide for more info.

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]
}

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.

Calling modalTransitionStyle from UITableViewController - nothing happens

I finally managed to trim my code and put all the TableViewController-Methods in a separate class (away from my ViewController). I had many problems which I already solved but there is one that puzzles me.
When a selection in the table occurs, I previously loaded a modalViewController, which worked fine. But now, as I put all the Table-methods in a separate class, the modal view simply does not load. It calls the function, and steps through it nicely when I select a row in the table, but there is no view loaded on the screen of my iPhone?!
Here is the code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
TaskViewController *taskViewController = [[TaskViewController alloc] initWithNibName:#"TaskViewController"
bundle:nil
task:[listOfEntries objectAtIndex:indexPath.row]];
taskViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentModalViewController:taskViewController animated:YES];
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
any suggestions?
Problems loading the NIB file? Not returning self from TaskViewController's init method? Are you sure taskViewController is not nil? Maybe you should call this on a parent navigationController? Are you setting UIModalPresentationFullScreen as the modal presentation style?

Resources