Teja Swaroop
Teja Swaroop

Reputation: 1159

Select first item in table view in ios

If count of the Array that tableview is using is 1 then how to select the first row in the table i used the following code it is selecting but not navigating to next screen

     NSIndexPath * ip =[NSIndexPath indexPathForRow:0 inSection:0];
    [npTable selectRowAtIndexPath:ip animated:YES scrollPosition:UITableViewScrollPositionNone];

Upvotes: 0

Views: 132

Answers (2)

Raja
Raja

Reputation: 61

you have to use some delegate methods for uitabelview

  1. you have to add UITableViewDataSource,UITableViewDelegate.
  2. You have to add the delegate method of uitabelview i.e)

Add delegate method as below.

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //here you have to write the code for to navigate next screen.
    sample *sampleobject=[[sample alloc]init];
    [self.navigationController pushViewController:sampleobject animated:YES];
}

that's it enjoy now u can naviagte to another page..

Upvotes: 2

JFoulkes
JFoulkes

Reputation: 2429

This only highlights the table cell. You would need to call the code which would appear in your tableView:didSelectRowAtIndexPath method or alternatively you could call it yourself like:

NSIndexPath * ip =[NSIndexPath indexPathForRow:0 inSection:0];
[self tableView: npTable didSelectRowAtIndexPath: ip];

Upvotes: 0

Related Questions