Показать UIPopoverController от кнопки раскрытия подробностей в UITableViewCell - PullRequest
3 голосов
/ 03 июля 2010

Я создаю приложение для iPad и хочу показать UIPopoverController со стрелкой, указывающей на кнопку раскрытия подробностей для строки, которой он принадлежит.Я хочу сделать это в методе tableView:accessoryButtonTappedForRowWithIndexPath:.В настоящее время у меня есть это, с фиктивной CGRect:

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
    // Dismiss in the case it shows itself somewhere else
    [addFeedPopup dismissPopoverAnimated:YES];

    // Set up
    TNSubscribeToFeedController *subscribeToFeedController = [[TNSubscribeToFeedController alloc] initWithNibName:@"SubscribeToFeed" bundle:nil];
    UINavigationController *subscribeToFeedNavigationController = [[UINavigationController alloc] initWithRootViewController:subscribeToFeedController];
    subscribeToFeedController.title = @"Subscribe to feed";
    subscribeToFeedController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:nil];
    subscribeToFeedController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:nil];
    /*
     * Note that we use the UINavigationController pure for the nices UINavigationBar.
     */

    // Show in popup
    addFeedPopup = [[UIPopoverController alloc] initWithContentViewController:subscribeToFeedNavigationController];
    addFeedPopup.popoverContentSize = CGSizeMake(480, 320);
    [addFeedPopup presentPopoverFromRect:CGRectMake(0, 0, 20, 20) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];

    // Memory
    [subscribeToFeedNavigationController release];
    [subscribeToFeedController release];
}

Кроме того, когда UITableView находится в режиме редактирования, кнопка раскрытия подробностей составляет около 60 пикселей слева, так как я использую этонастроить мои строки:

if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"SectionTwoCell"] autorelease];
}
cell.textLabel.text = [NSString stringWithFormat:@"Feed %d", indexPath.row];
cell.detailTextLabel.text = @"Description";
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
cell.editingAccessoryType = cell.accessoryType;
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^//
//        TWO LINES BACK DEAR SO USER        //

Может кто-нибудь помочь мне с этой проблемой?Спасибо.


О, а также возможно ли отключить прокрутку и отключить выбор чего-либо, пока UIPopoverController не закроется (перфекционизм)?

1 Ответ

9 голосов
/ 21 октября 2011

Чтобы сделать то, что вы хотите, вам нужен accessoryView, а параметр accessoryType не создает его.Однако это будет работать, если вы создадите кнопку и зададите ее как cell.accessoryView.

Создайте и установите accessoryView при создании ячейки:

    ...
    UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [disclosureButton addTarget:self action:@selector(discloseDetails:) forControlEvents:UIControlEventTouchUpInside];
    cell.accessoryView = disclosureButton;
    ...

Замените tableView: accessoryButtonTappedForRowWithIndexPath:с раскрытием деталей:Это похоже на то, что у вас было раньше, поэтому я внесу только следующие изменения:

- (void) discloseDetails:(UIButton *)sender {
    ...
    UITableViewCell *cell = (UITableViewCell *) sender.superview;
    NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];  // if needed
    [addFeedPopup presentPopoverFromRect:cell.accessoryView.bounds inView:cell.accessoryView permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
    ...
}

Если вам не нужна ячейка, ее можно сделать еще проще:

- (void) discloseDetails:(UIButton *)sender {
    ...
    [addFeedPopup presentPopoverFromRect:sender.bounds inView:sender permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
    ...
}

Вот как это выглядит

enter image description here

...