Reputation: 3784
I have a method constructed like this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//some table related stuff
}
However I cannot call this, so I basically copied and pasted the whole function and renamed as:
- (void)jumpCountry: (NSIndexPath *)indexPath {
//some table related stuff
}
and calling this method by using:
[self jumpCountry:countryIndex];
However my class looks ugly (and not preferred) because it has got the same two methods. So, how can I call the initial method directly(I know that it is assigned to a button which invokes that method). I am using iOS6.1. Basically, the reason why I want to directly call is I have another thread that listens notifications(from location services), once a notification is received, the table view should be changed. The notification itself already searches for NSIndexPath, so there won't be any problem with that.
Upvotes: 0
Views: 117
Reputation: 20021
To call programatically use
[tabelView selectRowAtIndexPath:scrollIndexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
Here scrollIndexPath
is the indexpath of row to be selected
For creating indexpath
NSIndexPath *scrollIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
Upvotes: 0
Reputation: 3960
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
This method a delegate method of table view from UITableViewDelegate
protocol and it gets call when user select a row in UITableView
. you should not call this method by your self.
instead of you can create your method and do whatever you want to do and call it in viewDidLoad
or any method.
Upvotes: 0
Reputation: 960
You can just put
[self jumpCountry:countryIndex];
to your method:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
Upvotes: 1