I have tableview with some names on each cell , how can i get that name when select row ?
i know that i have to use delegate method
-(void)tableView:(
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
NSString *cellText = selectedCell.textLabel.text;
}
This snippet retrieves the selected cell and stores its text
property in a NSString
.
However, I do not recommend this. It is better to keep the data and presentation layers separate. Use a backing data store (e.g. an array) and access it using the data in the passed indexPath
object (e.g. the index to use to access the array). This data store will be the same one used to populate the table.