Uitableview 越狱问题

Uitableview 越狱问题,uitableview,uipopovercontroller,Uitableview,Uipopovercontroller,尝试从已选择的tableView单元格显示我的popover UITableViewCell *cell; UserProfile *switchV = [[UserProfile alloc] initWithNibName:nil bundle:nil]; UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:switchV]; UIPopov

尝试从已选择的tableView单元格显示我的popover

UITableViewCell *cell;
 UserProfile *switchV = [[UserProfile alloc] initWithNibName:nil bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:switchV];
  UIPopoverController *pop = [[UIPopoverController alloc] initWithContentViewController:navController];
 [pop presentPopoverFromRect:cell.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
[开关V释放]


我做错了什么?

在“表格视图”单元格中有一个按钮,按下按钮时,希望显示指向该单元格的弹出框

首先,使用如下方式将按钮添加到cellForRowAtIndexPath中的单元格: 不必四舍五入为矩形

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setFrame:CGRectMake(100, 0, 100, 30)];
[button setTitle:@"Button" forState:UIControlStateNormal];
[button addTarget:self action:@selector(profileUser:) 
                         forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:button];
上面的一个要点是,在@selector中,profileUser后面有一个冒号,它告诉按钮将对自身的引用作为第一个参数发送给profileUser。此引用可用于确定选择了哪个单元格

profileUser:方法应如下所示:

-(void)profileUser:(UIButton *)button
{
    UITableViewCell *cell = (UITableViewCell *)[[button superview] superview];
    //first superview is cell.contentView
    //second superview is cell

    UserProfile *switchV = [[UserProfile alloc] initWithNibName:nil bundle:nil];
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:switchV];
    UIPopoverController *pop = [[UIPopoverController alloc] initWithContentViewController:navController];

    [pop presentPopoverFromRect:cell.frame inView:self.view 
        permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

    [switchV release];
    [navController release];

    self.popoverController = pop; //save in property for later release

    [pop release];
}
如果可能,将箭头方向保留为UIPopoverArrowDirectionAny,并让它找出放置它的最佳位置

编辑: 要显示箭头指向按钮而不是单元格的弹出框,请使用以下命令:

[pop presentPopoverFromRect:button.frame inView:cell 
    permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
但是,根据单元格在屏幕上的位置,popover可能看不到按钮的正下方。除非您确定结果,否则请使用Any而不是Up


另请注意,您应该保存对popover控制器的引用,以便在dealloc中稍后发布,否则方法中的[pop release]可能会导致崩溃。有关详细示例,请参见。

如果您在问题中发布代码,并解释发生了什么与您期望的情况会更好。我发布了它,它是粘贴链接:此代码是否在didSelectRowAtIndexPath中?您已经声明了单元格,但没有对其进行设置。您需要解释此按钮的位置,以及它如何与表视图中的单元格相关,以及从何处调用此代码。好的。因此,按钮位于UITableViewCell上,具有调用profileUser的操作。使用-voidprofileUser,我希望在弹出框中显示信息,并将其显示在所选的tableview单元格旁边。嘿,伙计,谢谢!现在,我如何使用按钮框架来显示它?说一下按钮在单元格上的什么位置,就在下面?我试着使用它的框架,但它只显示在最新的单元格上,其他单元格上没有。更新了答案。不知道你所说的最新手机上的节目是什么意思,而不是其他手机上的节目。