我已经实现了一个自定义的故事板segue,它在iOS 6下工作正常但在iOS 5.1下的模拟器中没有任何反应。 问题是popoverController在iOS 5.1下总是为零?
@implementation PopoverFromRectSegue
-(id)initWithIdentifier:(NSString *)identifier
source:(UIViewController *)source
destination:(UIViewController *)destination {
if(self = [super initWithIdentifier:identifier
source:source
destination:destination]) {
}
return self;
}
- (void)perform {
UIPopoverController *popCtrl = ((UIStoryboardPopoverSegue *)self).popoverController;
id controller = [self sourceViewController];
if ([controller isKindOfClass:[UIViewController class]] && [controller respondsToSelector:@selector(popoverRect)]) {
[popCtrl presentPopoverFromRect:[[controller performSelector:@selector(popoverRect)] CGRectValue] inView:[controller view] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}
@end
感谢任何帮助/提示。
编辑: 刚刚制作了新的样本项目。似乎在iOS5.1下没有设置popoverController 用于自定义UIStoryBoardSegues。 我还可以做些什么。 普通的popover需要一个锚,但不接受原型tableView单元格(编译时失败),我找不到修改弹出窗口的矩形的方法。
答案 0 :(得分:0)
这是我的解决方法 的 PopoverFromRectSegue.h 强>
@interface PopoverFromRectSegue : UIStoryboardPopoverSegue
@property (strong, nonatomic) UIPopoverController *popoverCtrl;
@end
PopoverRectFromSegue.m
#import "PopoverFromRectSegue.h"
@implementation PopoverFromRectSegue
- (void)perform
{
UIPopoverController *popCtrl = ((UIStoryboardPopoverSegue *)self).popoverController;
// under iOS 5.1 the popoverController iVar is not set
// so we have to use our own one
if (nil == popCtrl) {
popCtrl = self.popoverCtrl;
}
id controller = [self sourceViewController];
if ([controller isKindOfClass:[UIViewController class]] && [controller respondsToSelector:@selector(popoverRect)]) {
[popCtrl presentPopoverFromRect:[[controller performSelector:@selector(popoverRect)] CGRectValue] inView:[controller view] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}
@end
在我的prepareForSegue方法中,我执行以下操作。
if (isPad) {
self.popoverCtrl = [(UIStoryboardPopoverSegue *)segue popoverController];
if (nil == _popoverCtrl) {
self.popoverCtrl = [[UIPopoverController alloc] initWithContentViewController:[segue destinationViewController]];
((PopoverFromRectSegue *)segue).popoverCtrl = _popoverCtrl;
}
self.popoverRect = [NSValue valueWithCGRect:[self.myTableView rectForRowAtIndexPath:indexPath]];
}