This is what I am trying to do...but not sure how to do :
I have a tableview consisting of multiple rows in multiple sections. When I scroll the table going from 1 section to another, I want to do some other action - I want to have an action handler for this. But, I am not sure how to do it.
Cany anyone please help me out ? Thanks.
You can set the tableview delegate as the controller and implement this delegate function
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
This function will get called before a cell is going to be displayed. You can use the indexpath to check if it is going to be first item in a section.
Hope this helps.
Related
I have just added a UITableView in to my storyboard and the suggested constraints to it like that.. Now i have written very simple code with some delegate and datasource methods implemented like this. . Now when i tap the first row it detects nothing and check the console in the below image, when i press the second row it tells me that the indexPath.row is 0.. can some body point out that what i am doing wrong here.
You are calling -(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath which is called when you deselect row , instead call
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
It's because you are using didDeSelectRowAtIndexPath: instead of didSelectRowAtIndexPath: method.
You have to call "didSelectRowAtIndexPath" Delegate method.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
This method only return which row we have selected.
I'd like to use a delete button to call the delete row function in a TableView cell, just like the iPhone message app works.
The code I use to trigger this from a swipe will be familiar:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
[arrayLocations removeObjectAtIndex:indexPath.row];
[tableView reloadData];
}
But how do I call this code/functionality when pressing say a red circular delete button in the cell?
I'm not sure you want/should trigger this delegate yourself. Also remember that this delegate inserts / deletes cells so you need to check that editingStyle param. If you're adding a custom button you can simply route this to a custom method and delete the row.
Cell
Button action hit
Call a delegate
Table
Get the index with indexPathForCell
Adjust the data source array
Call begin updating, delete row, end updating
I was wandering if its possible to have more than one uiTableView in one ViewController.
For example:
tableView1 and tableView2 in one view controller.
Initial start up of view controller, tableView2 should be disabled and not visible.
tableView1 should show the data associated with it.
When user selects a row from tableView1... it should then show the data corresponding to the selected row in tableView2.
tableView1 should still be enabled, and if user selects another row, the contents of tableView2 should also change respectively.
Thanks for any help or guidance given. :)
Of course you can do this. This is 5 minutes in storyboard.
You should choose UIViewController (not UITableViewController!)
And create something like this:
Then you should create object references with a ctrl key.
You have to remember that you have to set delegate and dataSource in both tableViews to your ViewController:
And in yout second table view set initialView to hidden.
Then in your code in method - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath you should in first line call:
[self.mySecondTableView setHidden:NO]
and do all your stuff later. That's it.
EDIT:
Now i realize that you have set topic to "multiple" tableViews. This solution is messy enough for two TableViews. I suggest you to use container, and then all tableView will have own ViewController.
You can set different tags and outlets for this two TableView.
Then in
-(void)ViewDidLoad
self.yourSecondTableView.hidden = YES;
to hide second tableView
and when delegates methods was called
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
or
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
you can ask for tag like
if (tableView.tag == yourSecondTableViewTag)
return something
When i click the tableview i want to send the currentbook details to another viewcontroller "detailpage" and here its not sending any value?? why also it shows error?
error : unknown receiver "tableview"
Why are you creating two GMMDetailPage Objects? Also, you should most likely have self.tableView instead of just tableView. It would also be better to pass the tableView into the prepareForSegues:sender: method like so:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self performSegueWithIdentifier:#"bookItem" sender:tableView];
}
In my iPad app I'm using Apple's standard split view template. The master view has a table that's populated by a plist file and my table is split into three grouped sections. In my viewDidLoad method I've added the editbuttonitem that works as expected - tap it and you can then delete rows.
self.navigationItem.rightBarButtonItem = self.editButtonItem;
However, I'd like the editbuttonitem, when selected, to only allow editing in the last two sections and not the first. Is this possible? And if so, can someone help point me the way?
Or will I need to not use Apple's built-in mechanism for this and have to code a unique barbuttonitem that can perform this task?
Much appreciated.
Try implementing the editingStyleForRowAtIndexPath method:
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0)
return UITableViewCellEditingStyleNone;
else
return UITableViewCellEditingStyleDelete;
}