I have a class named FirstViewController which is a subclass of UIViewController and I have a UITableView in the class. I need to transition from this class to a new UIViewController subclass (using segues) when a row is pressed.
I have made the FirstViewController the UITableViewDelegate and UITableViewDataSource using the code –
@interface FirstViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
I am getting an error on this line of code –
NSIndexPath *path = [self.tableView indexPathForSelectedRow];
How do I fix this problem since the tableView is found in UITableViewController and not in UIViewController class ?
Edit –
Here’s the code related to my table view –
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [sarray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellId = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
if(cell == nil){
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
}
NSString *text = [sarray objectAtIndex:[indexPath row]];
cell.textLabel.text = text;
return cell;
}
You can simply declare tableView as a property: