Cell at UISearchController SearchTableView not responding to didSelectRowAtIndexPath - objective-c

I have a main table view with a search display controller. I'm using a custom cell.h which implement
(void)setSelected:(BOOL)selected animated:(BOOL)animated
When I select the cell from main table, the code above changes the background color of this selected cell. When I choose to search from the search bar, the search display controller display the selected cell in the correct background color using
(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
However, this cell which is displayed at the search display controller does not responds to didSelectRowAtIndexPath and didDeselectRowAtIndexPath. Other cells, on the other hand, responds to both methods.
What I want to achieve is a synchronization between the main table and the search table view at search display controller where selected cells should appear selected in both main table and search table view and yet allows selection and un-selection.
Please advice. Many thanks.

I found the answer to my question:
Use
(void)searchDisplayController:(UISearchDisplayController *)controller willShowSearchResultsTableView:(UITableView *)tableView
And
[tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:[searchResult indexOfObject:currentFriend] inSection:0] animated:NO scrollPosition:0];
Instead of
(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
Hope it helps!

Related

Objective-C linking two Tableviews

What I want is when you click on any cell in the table you go to another table view. I also need for each different cell you click on the view you get taken to has different strings. However I don't know
1) how to link a table cell to another tableview in the ViewController when you press it
2) how do you change the detail Tableview (including text and audio files) in View controller for each different cell you click on.
For detecting any row click in tableview use delegate method
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSLog(#"index path cell row number =======%ld",(long)indexPath.row);//you can get the index number of that cell
NSLog(#"data of clicked cell====%#",[yourArray objectAtIndex:indexPath.row]);//here you can get the data of that cell
}

How to click only one cell at a time like radio button in objective c

I am new in iOS and I am facing problem regarding to select one cell and on click of them change image. But when I click on other cell its image also got change.
As in image I can select all Full,Partial and None.I want to select only one at a time like radio button.
My code is like this
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
FPNTableViewCell *cell = (FPNTableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
cell.circleimg.image=[UIImage imageNamed:#"CircleClick.png"];
}
I am using Custom tableview. Thanks in Advance!
Initialise an Int (top of the controller Eg: int i=0;)
tableview didselect method assign the selected index to that int
EG: i = indexpath.row
Cellforrowindex method check the i with indexpath. Based on that you can use the image
You can use tableview method
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
for selecting.
-(void) tableView:(UITableView *)tableView didDeselectRowAtIndexPath:
(NSIndexPath *)indexPath {
}
for unselect.

How to always show tableView cell when i scroll

I need to always show cell with segmentControll, how can i do it?
There are a couple of ways to do this. Here is what I would do.
1
Don't put the segmented control as part of the table. Simply move it outside the UITableView. With that being said, if you are using a TableView Controller, you have to switch to a ViewController and add TableView to it.
2
This is a way to create a header for your table. Maybe that's what you want.
Use this method if you want a title:
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
Or this one if you want a custom view:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
And for the height:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

How reorder row in customize UITableViewCell

So far I have customized my UITableViewCell with the icon reorder row.
I want my cell can be reordered when long press on the reorder icon and then move it.
The image below is what I have expected.
I have read many document they provided only long press on cell and move it but I don't want it because long press on cell I have my another gesture is renaming it; and also I don't want to use the edit/done of UITableView default from OS; so I decided to put reorder icon but I can not do, because I'm new in objective c.
Can anyone help by providing sample code here?
Thank for reading.
Override two methods of UITableViewDataSource
For reordering to work you will first need to bring the Table in editing mode. Which you can either do it from viewDidLoad or from a IBAction method.
-(void) viewDidLoad{
[super viewDidLoad];
self.myTableView.editing = YES;
}
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath{
return YES;
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath{
//Manipulate your data array.
}
By Default editing style is UITableViewCellEditingStyleDelete. So if you don't override the below method it will show both rearrange as well delete icon.
-(UITableViewCellEditingStyle) tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewCellEditingStyleNone;
}
Since, you have long gesture of your cell causes issue with the long gesture of the re-ordering of cell. You can add a UIView to the cell. Add all your elements in this UIView. Now, attach a UILongPress Gesture to this UIView (not to the cell.).

How to show deleteConfirmationButton on a clicked UITableViewCell

I'm trying to make an UITableViewCell that shows the deleteConfirmationButton (while in edit mode) just like happens when I click at the editing controls but in my case I want it when the user clicks over the UITableCell.
I've already set the property AllowsSelectionDuringEditing to YES and I can delete the rows, I just want the deleteConfirmationButton to avoid any accident.
Any tips on how to do it?
Thanks!!
To do this you would probably use the commitEditingStyleForRowAtIndexPath function, which is called when an object is selected or deleted during editing.
- (BOOL)tableView:(UITableView *)tableView
canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
And then for the confirmation do something like this:
- (void)tableView:(UITableView *)tableView
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
//make a UIAlert and display confirmation, if yes then run the following code, if no then break
// remove the object
[myItems removeObjectAtIndex:indexPath.row];
// refresh the table view to display your new data
[tableView reloadData];
}