Reputation:
When a table view is pressed, I am trying to grab the value of a textview from that table view row that has been selected as follows.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{
tabBar = [self.storyboard instantiateViewControllerWithIdentifier:@"TabBarController"];
[self.navigationController pushViewController:tabBar animated:YES];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
MyOrdersController *detailVC = [[MyOrdersController alloc]init];
NSLog(@"hello %@", detailVC.shipmentReferenceNumberTextLabel.text);
}
But im getting null value. How can I get the value of the textview in that specific row?
Upvotes: 0
Views: 99
Reputation: 160
You can grab the textview from selected cell subview.
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
for (id txtView in selectedCell.subviews)
{
if ([txtView isKindOfClass:[UITextView class]])
{
UITextView* tv = (UITextView*)txtView;
NSString* text = tv.text;
}
}
}
Upvotes: 1
Reputation: 924
Just try it:-
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
NSString *cellText = selectedCell.textLabel.text;
}
Upvotes: 1