Iphone 在iOS 7中打开popviewcontroller时出错

Iphone 在iOS 7中打开popviewcontroller时出错,iphone,ios,ipad,uipopovercontroller,Iphone,Ios,Ipad,Uipopovercontroller,对我来说这看起来很简单,但我无法理解我犯了什么错误。我必须在我的iPad应用程序中点击行打开一个弹出窗口。我已经完成了以下代码: - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { popViewController *vc = [[popViewController alloc] initWithNibName:@"popViewController"

对我来说这看起来很简单,但我无法理解我犯了什么错误。我必须在我的iPad应用程序中点击行打开一个弹出窗口。我已经完成了以下代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    popViewController *vc = [[popViewController alloc] initWithNibName:@"popViewController" bundle:nil];
    vc.preferredContentSize = CGSizeMake(500,500);
    vc.view.frame = CGRectMake(0, 0, 500, 500);

    UIPopoverController *healthPopOver = [[UIPopoverController alloc] initWithContentViewController:vc];
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    [healthPopOver presentPopoverFromRect:cell.bounds inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
执行最后一行时,应用程序崩溃。我在网上搜索了很多网页,但我找不到原因。我没有得到任何具体的错误,只有主文件中的线程1错误


我正在使用iOS 7。

尝试将您的healthPopOverit添加到类中,因为
UIPopOvercontroller
必须保存在实例变量中

在.m中,将其定义为属性:

UIPopoverController *healthPopOver;
和变化:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    popViewController *vc = [[popViewController alloc] initWithNibName:@"popViewController" bundle:nil];
    vc.preferredContentSize = CGSizeMake(500,500);
    vc.view.frame = CGRectMake(0, 0, 500, 500);

    self.healthPopOver = [[UIPopoverController alloc] initWithContentViewController:vc];
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    [healthPopOver presentPopoverFromRect:cell.bounds inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

尝试将healthPopOverit添加为类的成员,因为
UIPopOvercontroller
必须保存在实例变量中

在.m中,将其定义为属性:

UIPopoverController *healthPopOver;
和变化:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    popViewController *vc = [[popViewController alloc] initWithNibName:@"popViewController" bundle:nil];
    vc.preferredContentSize = CGSizeMake(500,500);
    vc.view.frame = CGRectMake(0, 0, 500, 500);

    self.healthPopOver = [[UIPopoverController alloc] initWithContentViewController:vc];
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    [healthPopOver presentPopoverFromRect:cell.bounds inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

问题在于没有保留popover。按照@null的建议保留popover。问题在于不保留popover。按照@null的建议保留popover。非常感谢它的有效性。。。虽然我觉得很奇怪。你知道它为什么这样做吗?@pankaj我想你一定是在使用ARC。因此,在函数结束后,ARC将释放局部变量
healthpover
。此时可能会出现现金。
UIPopoverController
没有superview,除非您不保留它,否则任何人都不会保留它,因此通过执行
UIPopoverController*healthPopOver=[[UIPopoverController alloc]init…
变量超出范围,对象被释放,因为它不再有所有者,这就是你需要保留它的原因。非常感谢它工作了…虽然听起来很奇怪。你知道它这样做的原因吗?@pankaj我想你必须使用ARC。所以你的局部变量
healthPopOver
将被释放在
tableView:didSelectRowAtIndexPath:
函数结束后按圆弧进行d。此时可能会出现现金。
UIPopoverController
没有superview,除非您不保留它,否则任何人都不会保留它,因此通过执行
UIPopoverController*healthPopOver=[[UIPopoverController alloc]init…
变量超出范围,对象被释放,因为它不再有所有者,这就是为什么需要保留它。