Is there a simple way to detect if a UISearchBar is exiting "Search Mode"? - objective-c

I'm trying to set up a UISearchBarDelegate
My first attempt was to clear the search results when searchBarShouldEndEditing: was called, but I discovered that this gets called when scrolling through the search results, which is not a time to be getting rid of the array of them.
My next attempt is searchBarCancelButtonClicked: - but this doesn't get called if the search bar is empty and they tap the space below (where a greyed out view of the table view is showing).
So how do you know when to switch from returning search results cells to returning regular table view cells?
Thanks for any help with this.

You can check which table view is requesting the cells. searchDisplayController.resultsTableView is what requests your search results cells. Just check for this in cellForRowAtIndexPath

Related

NSTable/OutlineView: Edit textfield in a row without selecting the row

Context:
I have an NSOutlineView that acts like a source list, but does not use the actual source list highlighting style. (Imagine the sidebar in the Finder.)
This outlineView has only two levels: 1) "groups" and 2) "subitems". There is no additional nesting --- again, just like the source list in the Finder.
What I Want:
The top-level "group" rows in my OutlineView are NSTableCellViews with a single NSTextField. I would like my users to be able to edit the text in this textField (to rename the group) WITHOUT allowing them to select the entire group row in the OutlineView.
So far, I've not found a way to do this. If I prevent selection of group rows in my delegate for the OutlineView, it is not possible to edit the textfield. When I allow selection of the group rows, then I can get the textfield to edit just like any other.
Short of subclassing things and handling mouse events myself, is there a simple way to do this? Must a row in an NSTableView always be selected before textFields in that row can be edited?
I think it will work to use a custom subclass of NSOutlineView in which you override -validateProposedFirstResponder:forEvent: to return true if the proposed first responder is in a group row. Return whatever super returns for any other proposed first responder.
You can determine which row the proposed first responder is in by calling -rowForView:.
See this blog post from the Apple engineer who wrote the view-based table view stuff.

UITableView removing checkmark from cell on search

I am using a UITableView to display some items and i have implemented a UISearchBar to this UITableView.
If the user presses the cell, a checkmark appears (accessory type of the cell is changed) and when pressed again the checkmark accessory disappears.
My problem is when the user searches using the search bar, all the checked cells are not checked anymore, no more checked cells at all.
I've been trying to fix this and searching for it for a while but no results ...
Any help ??
Thanks you.
That is because your table view where you put the checkmarks and the table view that you see after you enter something in the search bar is not same. To have the same check marks on the search table view cells, you need to explicitly add the checkmarks.
I can't see the way you are adding and removing check marks. So, in theory, what you need is a way to know which cells have check marks. So, let's assume you have an array of items and a parallel array which holds the 1 or 0 to signal if the items have the check marks when 1 means check marked and 0 means no check mark.
Let's call this parallel array, checkMarkSignalArray. Now, in your cellForRowAtIndexPath method, you can do something like-
if(self.resultSearchController.active){
cell.textLabel.text = [self.filteredItemsArray objectAtIndex:indexPath.row];
if([self.checkMarkSignalArray objectAtIndex:indexPath.row]){
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
}

Handling tableview cell selection from other view controllers

I have a tableView with custom table cells which displays a list of sayings. While selecting a cell (say "saying1") from the tableView, the cell will get selected and will moves to next view controller for showing an explanation of selected saying. In that view controller two buttons "Previous" and "Next" are there for navigating to previous and next saying. So user may select next button for seeing next saying (say "saying2"). But the problem here is, In this stage when i navigate back to my tableview, the cell selected will be "saying1" not "saying2".
In order to solve this problem, i collected the currently selected sayings ("saying2's") index from array (ie,index will be 1) and passed it to the previous tableView through segue and converted that value into NSIndexpath. After this step i don't know what to do. Please help me in solving this.
You can specifically select a cell by calling following method present in UITableView class :
selectRowAtIndexPath:animated:scrollPosition:
refere to following link : https://developer.apple.com/library/ios/documentation/uikit/reference/UITableView_Class/Reference/Reference.html#//apple_ref/occ/instm/UITableView/selectRowAtIndexPath:animated:scrollPosition:

Array with selectItemAtIndexPath of a UICollectionView

I'm trying to programmatically select cells in a UICollection view. I'm new to Obj-C and I'm not quite sure how to use the selectItemAtIndexPath property. I can grab an array of the images the user has previously selected. It is just an array of numbers corresponding to named images. But I'm not sure how to use that information with selectItemAtIndexPath.
I've looked for examples of someone using
- (void)selectItemAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UICollectionViewScrollPosition)scrollPosition
But I'm not sure how to use it with my UICollectionView so I can have the right cells selected when the view loads and thus be highlighted. I have multiple selection on.
You should call selectItemAtIndexPath: for each cell you want to highlight, like so:
[self.collectionView selectItemAtIndexPath:path animated:NO scrollPosition:UICollectionViewScrollPositionNone]
Note that for one item (and one only!) you probably want to set the animated property to YES and provide a scroll position (one item only because otherwise you're going to be making a lot of needless animation calls).
You'll first need to get the index paths of the cells you want to select. The index path consists of two numbers: the section the cell is in and the row number (or order, if your collection view doesn't have rows) of the cell inside that section.
If you store the index paths of the cells the user has selected in an array then you can just iterate through. Otherwise you'll need to find the index path out, using a UICollectionView method such as indexPathForCell.

my DetailViewController has text field. It appears empty at my first tap after that

I have a table view which has full of items getting from my database. I open my app. I tap one of my items in table view, then DetailViewController that has only text field does not display anything it is empty. But when I go back to table view then tap any other item again , at this time it displays value what I wanted to display.. It does it for my only first tap.. I have no errors and warnings.. What am i missing?
Sounds like you implemented tableView:didDeselectRowAtIndexPath: instead of tableView:didSelectRowAtIndexPath:.