从UITableViewCell中的详细信息按钮显示UIPopoverController [英] Show a UIPopoverController from a detail disclosure button in a UITableViewCell
问题描述
我正在为iPad创建一个应用程序,我想要显示一个 UIPopoverController
,其箭头指向它所属行的详细信息按钮。我想在 tableView:accessoryButtonTappedForRowWithIndexPath:
方法中执行此操作。目前我有这个,有一个虚拟 CGRect
:
I am creating an application for the iPad, and I want to show an UIPopoverController
with an arrow pointing to the detail disclosure button for the row it belongs to. I want to do this in the tableView:accessoryButtonTappedForRowWithIndexPath:
method. Currently I have this, with a dummy 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像素左侧,因为我使用它来设置我的行:
Also, when the UITableView
is in editing mode, the detail disclosure button is about 60 pixels to the left, since I use this to set up my rows:
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 //
任何人都可以帮我问题?
Can anyone help me with this problem? Thanks.
哦,也可以禁用滚动并禁用选择,直到 UIPopoverController
是关闭的(完美主义)?
Oh, and is it also possible to disable scrolling and disable selecting anything until the UIPopoverController
is closed (perfectionism)?
推荐答案
设置accessoryType不创建一个。
To do what you want, you need an accessoryView and setting the accessoryType does not create one. However, it will work if you create a button and set it as the cell.accessoryView.
在创建单元格时创建并设置attachmentView:
Create and set the accessoryView when the cell is created:
...
UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[disclosureButton addTarget:self action:@selector(discloseDetails:) forControlEvents:UIControlEventTouchUpInside];
cell.accessoryView = disclosureButton;
...
替换tableView:accessoryButtonTappedForRowWithIndexPath:with disclosureDetails :.这看起来很像你以前的,所以我只把变化下面:
Replace tableView:accessoryButtonTappedForRowWithIndexPath: with discloseDetails:. This looks much like what you have before so I've only put the changes below:
- (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];
...
}
如果您不需要单元格,它可以更简单:
If you don't need the cell, it can be made even simpler:
- (void) discloseDetails:(UIButton *)sender {
...
[addFeedPopup presentPopoverFromRect:sender.bounds inView:sender permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
...
}
这是它的外观
>
这篇关于从UITableViewCell中的详细信息按钮显示UIPopoverController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!