在iPad上,用户可以使用-showFromBarButtonItem:animated:显示UIActionSheet。这很方便,因为它在操作表周围包装了一个UIPopoverController,并将弹出窗口的箭头指向传入的UIBarButtonItem。
但是,此调用会将UIBarButtomItem的工具栏添加到直通视图列表中-这并不总是令人满意的。而且,如果没有指向UIPopoverController的指针,就无法将其他视图添加到直通列表中。
有没有人知道一种获得批准的方法来获取popover控制器的指针?
提前谢谢。
发布于 2010-05-12 19:23:04
您需要在方向更改时进行调整。
我找到了另一种解决方案,它对我来说非常有效。
坚持
- (void)showFromBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated
在您的@接口中添加
UIActionSheet *popoverActionsheet;
还可以添加
@property (nonatomic, retain) UIActionSheet *popoverActionsheet;
还可以添加
- (IBAction)barButtonItemAction:(id)sender;
因此,您可以从实现中任何位置引用您的操作表。
在您的实现中
- (IBAction) barButtonItemAction:(id)sender
{
//If the actionsheet is visible it is dismissed, if it not visible a new one is created.
if ([popoverActionsheet isVisible]) {
[popoverActionsheet dismissWithClickedButtonIndex:[popoverActionsheet cancelButtonIndex]
animated:YES];
return;
}
popoverActionsheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:@"Save Page", @"View in Safari", nil];
[popoverActionsheet showFromBarButtonItem:sender animated:YES];
}
在actionsheet委托实现中
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex == [actionSheet cancelButtonIndex]) return;
//add rest of the code for other button indeces
}
别忘了在
- (void)dealloc
我相信这会行得通。
发布于 2011-05-04 19:40:17
if ([[[[actionSheet superview] superview] nextResponder] respondsToSelector:@selector(setPassthroughViews:)]) {
[[[[actionSheet superview] superview] nextResponder] performSelector:@selector(setPassthroughViews:) withObject:nil];
}
这应该不会对应用程序审查者造成任何问题,因为它不会调用任何私有App。
它是脆弱的- if语句确保你的代码不会在苹果改变底层实现的情况下崩溃(只是不工作)。
发布于 2010-05-13 17:29:35
我怀疑是否有批准的方法来解决这个问题,因为操作单是用UIPopoverViews呈现的,它链接到UIViewController,而不是UIPopoverController
NSLog(@"%@",[[[popoverActionsheet superview] superview] passthroughViews]);
查看UIPopoverView头文件(未记录)会产生以下解决方案,尽管没有记录。如果你觉得值得一试的话,我想你可以跳过应用评审员的审核。
http://github.com/kennytm/iphone-private-frameworks/blob/master/UIKit/UIPopoverView.h
NSArray *passthroughViews = [[[popoverActionsheet superview] superview] passthroughViews];
NSMutableArray *views = [passthroughViews mutableCopy];
[views addObject:[self view]];
[[[popoverActionsheet superview] superview] setPassthroughViews:views];
[views release];
https://stackoverflow.com/questions/2806988
复制相似问题