0
我有一个表视图。当一个tableview单元格被点击时,im抓取一个特定的文本标签值。在APIRequest.m文件中,我有一个变量shipmentReferenceNo
,它的值im在didSelectRowAtIndexPath上指定为textlabel值。无法通过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,其空
NSLog(@"sd %@",self.shipmentReferenceNo);
可能是什么,虽然我已经在didSelectRowAtIndexPath
先前分配用于这项空值可能的原因?
这是因为您正在再次创建新实例。 self.request = [[APIRequest alloc] init];你只是删除它。因为你已经宣布self.request作为一个财产!你也需要寻找self.request.shipmentReferenceNo和不self.shipmentReferenceNo –
我试过了,但仍然即时通讯有相同的问题 – user1241241
在didSelect方法中放置一个断点并尝试在调试器中打印self.request的值。 –