how to get title of of row selected in UITableview

后端 未结 5 640
孤独总比滥情好
孤独总比滥情好 2021-02-04 03:44

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:(         


        
5条回答
  •  渐次进展
    2021-02-04 04:20

    -(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.

提交回复
热议问题