我正在尝试更新我的应用,以便它适用于iOs7。
在iOS 5& 6这完美地运作了:
if ([segue.identifier isEqualToString:@"popover"])
{
FavoritesViewController *vc = segue.destinationViewController;
CGFloat width = 200.0;
CGRect rect = [vc.tableView rectForSection:[vc.tableView numberOfSections] - 1];
CGFloat height = CGRectGetMaxY(rect);
if ([segue isKindOfClass:[UIStoryboardPopoverSegue class]])
{
_filterPopoverController = [(UIStoryboardPopoverSegue *)segue popoverController];
[_filterPopoverController setPopoverContentSize:CGSizeMake(width, height)];
[_filterPopoverController setDelegate:self];
}
}
}
我用它来检查它是否已经在屏幕上
- (IBAction)touchedFilterButton:(UIBarButtonItem *)sender
{
if (_filterPopoverController == nil)
{
[self performSegueWithIdentifier:@"popover" sender:self];
}
else
{
[_filterPopoverController dismissPopoverAnimated:YES];
_filterPopoverController = nil;
}
}
如果我删除此行
_filterPopoverController = [(UIStoryboardPopoverSegue *)segue popoverController];
它可以工作,但我无法设置宽度/高度,并且不会检查它是否在屏幕上。
答案 0 :(得分:1)
问题是iOS7不那么“原谅”
我打电话
_filterPopoverController = [(UIStoryboardPopoverSegue *)segue popoverController];
之后
CGFloat width = 200.0;
CGRect rect = [vc.tableView rectForSection:[vc.tableView numberOfSections] - 1];
CGFloat height = CGRectGetMaxY(rect);
高度总是0.000,因为它还没有“显示”,所以我必须在调用另一个视图控制器并设置宽度后替换segue。 我删除了子类部分因为它已经是肯定的子类
FavoritesViewController *vc = segue.destinationViewController;
_filterPopoverController = [(UIStoryboardPopoverSegue *)segue popoverController];
CGFloat width = 200.0;
CGRect rect = [vc.tableView rectForSection:[vc.tableView numberOfSections] - 1];
CGFloat height = CGRectGetMaxY(rect);
[_filterPopoverController setPopoverContentSize:CGSizeMake(width, height)];
[_filterPopoverController setDelegate:self];