iphone - 从 UITableViewCell 中的详细信息公开按钮显示 UIPopoverController

标签 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];
}

此外,当 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 关闭(完美主义)?

最佳答案

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

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

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

将 tableView:accessoryButtonTappedForRowWithIndexPath: 替换为 recognizeDetails:。这看起来很像您之前的内容,因此我仅将更改放在下面:

- (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

关于iphone - 从 UITableViewCell 中的详细信息公开按钮显示 UIPopoverController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3171637/

相关文章:

ios - 在 iOS 中对 pdf 文档进行数字签名

iphone - 检测 UIImagePickerController 中的方向变化?

iphone - 我怎样才能像 UIActionSheet 一样从屏幕底部呈现一个 UIView?

ios - 根据计时器调整表格 View 单元格文本

ios - 重用 UITableViewCell 移动 subview 框架

iphone - 使用 UIView 动画时处理、删除和添加 UILabels

iphone - 当 UIView 低于 EAGLView 时,我的性能是否会受到很大影响?

iphone - 如何截取整个 View 的 iPhone 屏幕截图,包括屏幕外的部分?

iphone - 在核心图折线图中旋转数据标签

ios - 你如何将一个类从 Swift 传递到 Cocoa 中以便使一个新的 UITableViewCell 出队?