无法通过 didSelectRowAtIndexPath 传递值

Unable to pass values through didSelectRowAtIndexPath

我有一个 table 观点。单击 table 视图单元格时,我会抓取特定的文本标签值。在 APIRequest.m 文件中,我有一个变量 shipmentReferenceNo,我将其值分配为 didSelectRowAtIndexPath 上的文本标签值。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{
    tabBar = [self.storyboard instantiateViewControllerWithIdentifier:@"TabBarController"];
    [self.navigationController pushViewController:tabBar animated:YES];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    UILabel *label = (UILabel *)[cell viewWithTag:123123];
    self.request = [[APIRequest alloc]init];

    self.request.shipmentReferenceNo = label.text;

    NSLog(@"hello %@",  label.text);

}

当我尝试按如下方式从 APIRequest.m 文件访问 shipmentReferenceNo 时,它为 null

NSLog(@"sd %@",self.shipmentReferenceNo);

虽然我之前在 didSelectRowAtIndexPath 中分配了这个空值,但可能是什么原因造成的?

试试这个代码

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
 {
   [tableView deselectRowAtIndexPath:indexPath animated:YES];
   UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
   UILabel *label = (UILabel *)[cell viewWithTag:123];
   self.request = [[APIRequest alloc]init];
   self.request.shipmentReferenceNo = label.text;
   NSLog(@"hello %@",  label.text);

  dispatch_async(dispatch_get_main_queue(), ^{
  tabBar = [self.storyboard instantiateViewControllerWithIdentifier:@"TabBarController"];
  [self.navigationController pushViewController:tabBar animated:YES];
 });

}

也在table里面查看数据源:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   UITableViewCell *cell = ;
  [cell.label setTag:123];
}

这可行,但我建议通过将 dispatch_async 代码移动到单独的方法来使您的代码更有条理。