开发者

How to get values in a tableview cell

开发者 https://www.devze.com 2023-04-09 01:49 出处:网络
I have a tableview cells containing bible verses one by one in each cell,my need is when the user tap the cell i have to get the verse inside the tapped cell in 开发者_运维技巧a string formate.this is

I have a tableview cells containing bible verses one by one in each cell,my need is when the user tap the cell i have to get the verse inside the tapped cell in 开发者_运维技巧a string formate.this is for sharing functionality. Please help me.


To add the verse, you likely used

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

To get the verse back from a tapped cell, you use

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;

When filling the tableView, you used indexPath to get the right verse - thats what you want to do now again. Assuming you have a NSArray called 'verses':

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  NSString *verse = [verses objectAtIndex:indexPath.row];
  NSLog(@"The selected verse is: %@",verse);
}


If verse is already in a standard UITableViewCell, you can access it via UITableViewCell property, like cell.textLabel.text or cell.detailTextLabel.text. Examine UITableViewCell class reference.


use the same array to get the string.... In didSelectRowAtIndexPath delegate

have a code like this

NSLog(@"%@",[NSString stringWithFormat:"%@",[yourArray ObjectAtIndex:indexPath.row]);

You can also use the above code to get the string in a NSString variable.

0

精彩评论

暂无评论...
验证码 换一张
取 消