user831679
user831679

Reputation:

Iphone tableview

I am using below code for getting index number of the row. I want to get the Text of row. Please tell me, what modifications are required to get the text from each row.

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *__strong)indexPath{

    DetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"Detail"];
    [self.navigationController pushViewController:detail animated:YES];

    detail.rowNum.text = [NSString stringWithFormat:@"Row: %d", (indexPath.row) ];
}

thanx in advance :)

Upvotes: 2

Views: 561

Answers (2)

Evgeny Aleksandrov
Evgeny Aleksandrov

Reputation: 779

You can get cell with all its properties this way:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *__strong)indexPath{
    DetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"Detail"];

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

    detail.rowNum.text = [NSString stringWithFormat:@"Row: %d", (indexPath.row) ];
    detail.someLabel.text = cell.textLabel.text;

    [self.navigationController pushViewController:detail animated:YES];
}

Is this what you want? Text from selected cell?

Upvotes: 1

iamsult
iamsult

Reputation: 1579

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *__strong)indexPath{

    DetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"Detail"];
    [self.navigationController pushViewController:detail animated:YES];
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    NSString *cellText = cell.textLabel.text;
    detail.rowNum.text = cellText;
}

Update ur code as above.

Upvotes: 0

Related Questions