如何从didSelectRowAtIndexPath上的UITableView获取textview的值?

时间:2016-04-25 12:35:22

标签: ios objective-c iphone uitableview

当按下表格视图时,我试图从已选择的表格视图行中获取textview的值,如下所示。

- (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);

}

但我得到空值。如何获取该特定行中textview的值?

2 个答案:

答案 0 :(得分:2)

试一试: -

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

答案 1 :(得分:2)

您可以从选定的单元格子视图中获取文本视图。

-(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;
        }
    }
}