Получение значения определенной текстовой метки и создание json в didSelectRowAtIndexPath

Ниже приведен мой метод cellForRowAtIndexPath в файле MyOrdersController.m...

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    UITableViewCell *cell = nil;
    cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:@""];

    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                      reuseIdentifier:nil];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }

    self.shipmentReferenceNumberTextLabel = [[UILabel alloc]init];

    self.shipmentReferenceNumberTextLabel.text = amountArray[indexPath.row];
    self.shipmentReferenceNumberTextLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:10];


    tableView.tableFooterView = [UIView new];

    cell.layer.borderWidth = 1.0;
    cell.layer.cornerRadius = 10;
    cell.layer.borderColor = [UIColor blackColor].CGColor;

    [cell.contentView addSubview:self.productAmountLabel];
    [cell.contentView addSubview:self.productAmountTextLabel];

    return cell;
}

У меня есть текстовая метка shipmentReferenceNumberTextLabel в этом. Я должен схватить ценность shipmentReferenceNumber когда пользователь нажимает на определенную ячейку, и я должен сделать запрос json с ней в файле с именем APIRequest.m. Я пытаюсь получить его значение следующим образом,

- (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(@"%@",  detailVC.shipmentReferenceNumberTextLabel.text);

}

Проблема в том, что его печать null в то время как я пытаюсь захватить его значение. Как я могу решить эту проблему.

1 ответ

Решение

Вы можете получить значение Lable из массива.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{
      NSLog(@"%@",amountArray[indexPath.row]);
}

Вы получите значение метки выбранной строки.

Другие вопросы по тегам