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的值。 –