SearchBar Display Controller not showing UITableViewCellAccessoryCheckmark on search result - uisearchdisplaycontroller

I am working on check and uncheck of table view cell however my code is working fine without search display controller. When I use Search Bar display controller I am getting search result and when I click on search result details "THERE IS NO CHECK ICON" and If part is not called "if (tableView == self.searchDisplayController.searchResultsTableView)" Below is my Code..I am not able to attache my source code.
Only problem is I am not able to add check icon on cell when clicked on cell in search results only..when I remove text from search results I am able to see check icon. Please help
Thanks In advance

Looks like at the end of your tableView:didSelectRowAtIndexPath you are reloading the wrong tableview. See where you wrote [self.tableView reloadData]? Try changing that to
// At the end of tableView:didSelectRowAtIndexPath...
[tableView reloadData] // Reload the tableView that was updated
Or, inside of the if condition for checking if it's the search table that was selected...
[self.searchDisplayController.searchResultsTableView reloadData];

Related

UITableView deselect selected cells after editing

I have multiple cells selected in a UITableView, but they automatically get deselected after editing. I searched a bit and I saw people saying that they called 'reloadData' which has caused the selections to be removed, but I do not call reloadData anywhere except for in 'viewDidAppear'. They get deselected even if the editing has been cancelled without changing anything (when clicking 'edit' button in the toolbar then clicking 'done' button without any editing). I'm not sure where this is happening. Or, if I could detect when the editing has been finished (when 'done' button has been clicked), I could simply reselect all the cells that had been selected, but I'm not sure how I could detect it..
How could I prevent the cells from getting deselected? Or reselect the cells after the edit?
Thanks in advance.
I presume you are trying to achieve selection and deselection on Button press, If you are trying to change the state of selection in a UITableViewCell try using the method in the button action.
-(IBAction) someAction {
if(buttonToggled){
[tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
}else{
//Do something
}
}
for changing the backgroundColor.
cell.selectionStyle = UITableViewCellSelectionStyleGray;
cell.selectedBackgroundView.backgroundColor=[UIColor blackColor];
for more information on the above please check the link.
UITableView Cell selected Color?
I would suggest the best bet is just to reselect them yourself after every press on your "done" button.
It is quite normal that cells get deselected or buttons get unpressed, since this is their normal state - exept if you write your own code to change this - like in your case.
This is how to select a row:
[tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
If you have multiple rows that can be selected make sure you have the settings accordingly, otherwise it might always deselect all but the most recent rows.
Nevermind. I found out that - (void)setEditing:(BOOL)editing animated:(BOOL)animated gets called whenever the 'edit' or the 'done' button has been clicked.

iPhone - changing contents of a UITableViewCell inside a navigationController

I have a UITableView with some cells in it that have people's names. When the user clicks on a cell, the Navigation Controller pushes a new view onto the stack that shows detailed info for that person. When the user is done and clicks the button to return to the previous view, the tableview is again shown. The problem is that I want to edit the cell text (or just mark the cell in some way) to show that the user has clicked on that cell. In my cellForRowAtIndexPath: method I have set up code that should change the text of the cell after a user clicks on that cell. I set up break points and it IS entering cellForRowAtIndexPath: when the detail view is popped and the tableview is again shown. It's entering the segment of code in cellForRowAtIndexPath: that should change the text, but when it comes up on screen, the text has not been changed. Does anyone have any ideas as to what is going on? Thanks.
EDIT: I figured it out. I just needed to call [tableView reloadData]; instead of calling the cellForRowAtIndexPath method. Not sure why that works differently, but it fixed it.
I guess I'll help you out. You don't need to credit me with the answer though.
cellForRowAtIndexPath:
that method is called within the framework when a cell is being refreshed from the queue or when it needs to be created. You should not call this method.
[tableView reloadData];
that method is basically a refresh on all of the visible cells show in the UITableView. This is the method you should call if you change information in your data source or you need to (force) update the appearance of your cells.
It's Good You Have Reload Table And Changed The Text But If YouJustIndicate NAd Don't Want To Change The Text The nYou Can Use elow Given Text ....
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
It Will Check Mark Particuler Cell Which You Click/Visited......
Hope You Like This Solution.....

How can we put a checkbox in uitableviewcell

I created list of todos. Now I want to put the checkbox for each one cell. When I mark it as checked, it can be marked and then we select delete button if we want, which is also in the same cell at right side and deleted, but I am not able to perform action like this.
Can anyone please help me?
#Chakradhar not a big issue you can do it very easily with or without using custom images.
In your didSelectRowAtIndexPath delegate try to check and set the UITableViewCellAccessory as per your condition.
This is the way in which there is no need to use extra images and you can checked for you particular selected cell:
if (//here you check)
{ // item needed - display checkmark
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{ // not needed no checkmark
cell.accessoryType = UITableViewCellAccessoryNone;
}
Take this shopping tutorial and see didSelectRowAtIndexPath delegate method see how they had used the condition.
Edited as per your last comment: For custom accessory view look for Implement a Custom Accessory View For UITableView in iPhone
Good Luck!
Use this
cell.accessoryType = UITableViewCellAccessoryCheckmark;
You can actually add custom button with an unchecked image on your cell. On button action method you can change the image to checked & handle rest of the things you want to handle.

Why my tableView doesn't update without scrolling it down?

I am making an nav based app. in my table view i am parsing a xml and showing its data. when i enter new feed item in my xml and click refresh button, my data updates but it didn't appear in tableView untill i scroll it down. When i scroll it down it appears. Can anybody tell me why its happening like that? I want new data appear when i enter the feed item without scrolling my tableView down. Thanx for help
you need to call [self.tableView reloadData] to update the tableView with new contents
Did you call [tableView reloadData] when the data has been refreshed?
You need to reload the cells (or the entire table) for the new data to appear.
Depending on if you return parsed results right away or all results after the entire xml-file has been parsed.
The code to update the table is:
[myTableView reloadData];
You have to call [tableView reloadData] to refresh the data from the UITableView.
Call [tableView reloadData] when the parsing is completed
I'm not exactly sure what you mean. A simple reload is:
[myTableView reloadData]
in the UITableViwController
[self.tableView reloadData]
If you scroll down, new cells that are rendered will use the new data. but cells that are on display have to be told to update immediatly.
Not just -reloadData, you can use any of these:
reloadData
reloadRowsAtIndexPaths:withRowAnimation:
reloadSections:withRowAnimation:
reloadSectionIndexTitles
Basically, you'll need to tell your tableview that your data has changed so it knows to change that. You can do it with fancy animations and whatnot so that the user isn't confused when what's displayed on screen suddenly changes.

Reloading / Displaying searchResultsTableView of UISearchDisplayController after search method iteration is finished

I have modified the code of Apple's sample iOS project TableSearch in order to use it for searching a webservice by parsing its contents. Everything I have implemented works fine except for one ugly detail when performing a search using the SearchDisplayController's SearchBar. I have changed the behaviour of the SearchDisplayController to make it call my search function first when the "Search" button was tapped.
The problem is that when the search iteration (which is performed in the background in an NSOperationQueue) is finished the "searchResultsTableView" (of the searchDisplayController) is not automatically displayed or not assigned the resulting content. If you then change the SearchBar's text or tap the "Cancel" button from the view which appears when you touch the search field (see TableSearch) the correct TableView appears with the search results. I simply want to have this step to be executed right after the search operation is finished, so before you interact. At this stage the "No Results" label is currently displayed. The methods "filterContentForSearchText" and "shouldReloadTableForSearchString" are unchanged from the original TableSearch project.
I have taken a look at different class references of the SearchDisplayController and its attributes but I could not find any final solution yet.
I have tried the following in a section which is definitely iterated after the NSOperation is finished but it does not seem to solve the problem.
[self.searchDisplayController.searchResultsTableView removeFromSuperview];
and
self.searchDisplayController.searchResultsTableView.hidden = YES;
These operations both have the correct view I want displayed BUT scrolling is disabled until you change the state so that the view is hidden again. It is possible to select TableView cells, though. I basically want to have this just with scrolling enabled...
Thanks in advance for your effort!
I have same problem and I just solved it. I had exactly same problem, I wanted disable instant search and when I hit search button, the table didn't load but when I clicked cancel, it loaded up. And If I scroll on table view that didn't load correct result after search, it crashed due to index out of bound.
The thing you need to do is reload searchResultTableView not current tableview. After you filter out your data by search term, put
[self.searchDisplayController.searchResultsTableView reloadData]
to reload your search result, and it will shows up after you hit search button.
Hope this help
I found that setting the searchBar.text causes searchDisplayController.searchResultsTableView be added to self.view, I solve it like this:
self.searchBar.text = #"xxxx";
[self.searchDisplayController.searchResultsTableView removeFromSuperview];