Подтвердить что ты не робот

Как получить текст ячейки на основе indexPath?

У меня есть UITabBarController с более чем 5 UITabBarItems, поэтому доступен доступ к функции moreNavigationController.

В моем UITabBarController Delegate я делаю следующее:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
//do some stuff
//...

UITableView *moreView = (UITableView *)self.tabBarController.moreNavigationController.topViewController.view;
    moreView.delegate = self;
}

Я хочу реализовать UITableViewDelegate, чтобы я мог захватить выбранную строку, установить собственное свойство вида и затем нажать контроллер вида:

- (void)tableView:(UITableView *)tblView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
  //how can I get the text of the cell here?
}

Мне нужно получить текст ячейки, когда пользователь нажимает на строку. Как я могу это сделать?

4b9b3361

Ответ 1

- (void)tableView:(UITableView *)tblView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
      //how can I get the text of the cell here?
      UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
      NSString *str = cell.textLabel.text;
}

Лучшим решением является сохранение массива ячейки и использование его непосредственно здесь.

    // Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }

    Service *service = [self.nearMeArray objectAtIndex:indexPath.row];
    cell.textLabel.text = service.name;
    cell.detailTextLabel.text = service.description;
    if(![self.mutArray containsObject:cell])
          [self.mutArray insertObject:cell atIndex:indexPath.row];
    return cell;
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell = [self.mutArray objectAtIndex:indexPath.row];
    NSString *str = cell.textLabel.text;

}