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:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
but how can i get that title of that row ?
thanks in advance
regards
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...
..if this is really what you require.
you can access each row of your uitabelview using the following (uitableview-)function:
by the way, to access your tableview in other methods than uitableview's delegate method, you have to hook it up in IB (for example..)
hope it helps
This snippet retrieves the selected cell and stores its
text
property in aNSString
.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.Here,
[tableView cellForRowAtIndexPath:indexPath] gives you the selected cell and then the .textLabel.text gives you the label for that cell.
Assuming you're using a standard UITableViewCell, you can get the cell by using
then access the text property view properties via: