从UITableViewCell中的详细信息披露按钮显示UIPopoverController

3 iphone cocoa-touch uitableview uipopovercontroller

我正在为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];
}
Run Code Online (Sandbox Code Playgroud)

此外,当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        //
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮我解决这个问题吗?谢谢.


哦,是否也可以禁用滚动并禁用选择任何东西,直到UIPopoverController关闭(完美主义)?

lam*_*bmj 9

要做你想做的事,你需要一个accessoryView并设置accessoryType不会创建一个.但是,如果您创建一个按钮并将其设置为cell.accessoryView,它将起作用.

创建单元格时创建并设置accessoryView:

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

使用disclosureDetails:替换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];
    ...
}
Run Code Online (Sandbox Code Playgroud)

如果您不需要单元格,可以使其更简单:

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

这是它的样子

在此输入图像描述