Objective-C linking two Tableviews - objective-c

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
}

Related

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.

objective c: exchange cell across sections

I have a tableview contain many sections, in each of section, there is one cell, what I want to do is, when enter the editing mode, I will drag and drop one cell to another section, and I wish when drag is finished, the origin cell in target section will auto exchange to the section which the cell moved out.
Here's the code I did test, but didn't work
-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
NSInteger destRow=destinationIndexPath.row;
NSInteger srcRow=0;
NSIndexPath *srcIndexPath=[NSIndexPath indexPathForRow:srcRow inSection:destinationIndexPath.section];
UITableViewCell *cell=[self.tableView cellForRowAtIndexPath:srcIndexPath];
[cell.textLabel setText:#"aaa"];// test if I got right cell, the result is ok.
NSIndexPath *trgIndexPath=[NSIndexPath indexPathForRow:0 inSection:sourceIndexPath.section];
[self.tableView moveRowAtIndexPath:srcIndexPath toIndexPath:trgIndexPath];
}
Kindly help me to check if there is any solutions, thanks!

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.).

Cell at UISearchController SearchTableView not responding to didSelectRowAtIndexPath

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!

How to define a table view cell in storyboard for use in code?

I have a TableViewController on my storyboard that has some cells (static) that I want to add a checkmark to when the cell is tapped, how would I be able to call the individual cells from the storyboard without having to build them in code?
in the delegate of your table view:
- (void)tableView:(UITableView *)tv didSelectRowAtIndexPath:(NSIndexPath *)ip
{
MyCustomCell *cell = [tv cellForRowAtIndexPath:ip];
// add the checkmark to the cell
[cell.contentView addSubview:checkmarkIcon];
}