how to get title of of row selected in UITableview

后端 未结 5 620
孤独总比滥情好
孤独总比滥情好 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:13

    Once you've registered one of your classes as a delegate via the UITableView delegate property you simply implement the tableView:didSelectRowAtIndexPath: method, which would be called when the user selected a row. (See the UITableViewDelegate Protocol Reference for more information.)

    You could then extract the label text from the selected cell via...

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
        {
            UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
            NSString *cellLabelText = cell.textLabel.text;
        }
    

    ..if this is really what you require.

提交回复
热议问题