Ios UtableView内的popover将不会滚动

Ios UtableView内的popover将不会滚动,ios,uitableview,scroll,uipopovercontroller,uipopover,Ios,Uitableview,Scroll,Uipopovercontroller,Uipopover,我试图修复某人的代码,但遇到了问题。情况如下: 我有一个全屏UIViewController,它有一个底部的工具栏按钮。当我按下该按钮时,屏幕左下角会显示一个弹出视图控制器。弹出窗口中的视图控制器也有一个按钮,当我按下该按钮时,它会将一个新的视图控制器推到弹出窗口中。新的视图控制器是一个UITableView,它可以有一些大量的元素。问题是,当我试图向下滚动以查看一些屏幕外的元素时,滚动会反弹回表中的第一个位置,即,它不会真正滚动 更具体地说,这里有一些代码: 在FullScreenVC.h中:

我试图修复某人的代码,但遇到了问题。情况如下: 我有一个全屏UIViewController,它有一个底部的工具栏按钮。当我按下该按钮时,屏幕左下角会显示一个弹出视图控制器。弹出窗口中的视图控制器也有一个按钮,当我按下该按钮时,它会将一个新的视图控制器推到弹出窗口中。新的视图控制器是一个UITableView,它可以有一些大量的元素。问题是,当我试图向下滚动以查看一些屏幕外的元素时,滚动会反弹回表中的第一个位置,即,它不会真正滚动

更具体地说,这里有一些代码:

在FullScreenVC.h中:

@property (nonatomic, retain) NSMutableArray* stuffInList;
@property (nonatomic, retain) UIPopoverController *namePopover;
@property (nonatomic, retain) UINavigationController *nameNav;
@property (nonatomic, retain) UIBarButtonItem* addButton;
按下FullScreenVC按钮(按下addButton时调用):

换句话说,第一个POPUPVC对象vc是UINavigationViewController nameNav的根视图控制器,而nameNav是navigationcontroller,它是namePopover UIPopoverController中的内容。我认为最后一行将FirstPopupVC作为addButton的弹出窗口启动。还要注意,XIB文件FirstPopupVC.XIB是一个简单的NIB文件,它有几个简单的视图(标签等)和一个用户可以按下的小按钮,以获得第二个弹出窗口,我们将看到

在FirstPopVC内部,我们有:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // some other irrelevant initialization stuff here ...

        self.contentSizeForViewInPopover = CGSizeMake(320, 340);
    }
    return self;
}


-(void)littleButtonClicked:(id)sender {
    SecondPopupVC * secondVC=[[SecondPopupVC alloc] 
          initWithNibName:"@SimpleTableView" bundle"nil];
    secondVC.delegate=self;
    secondVC.stuffInList=self.stuffInList;
    [self.navigationController pushViewController:secondVC animated:YES];
    [secondVC release];
}
- (id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.contentSizeForViewInPopover = CGSizeMake(320, 340);

    }
    return self;
}
当然,这将显示popop中的第二个视图控制器

在第二个UPVC中,我们有:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // some other irrelevant initialization stuff here ...

        self.contentSizeForViewInPopover = CGSizeMake(320, 340);
    }
    return self;
}


-(void)littleButtonClicked:(id)sender {
    SecondPopupVC * secondVC=[[SecondPopupVC alloc] 
          initWithNibName:"@SimpleTableView" bundle"nil];
    secondVC.delegate=self;
    secondVC.stuffInList=self.stuffInList;
    [self.navigationController pushViewController:secondVC animated:YES];
    [secondVC release];
}
- (id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.contentSizeForViewInPopover = CGSizeMake(320, 340);

    }
    return self;
}
显然,这里的contentSizeForViewInPopover调用将使用表视图设置popover视图的大小。在第一个和第二个视图控制器中,这看起来像是在initWithNibName内部调用的

同样,问题是,如果我的listOfStuff很大,即如果表中的项目集很大,那么表将不会保持滚动超过第一组可见的行。我可以向下滚动查看这些项目,但只要我松开鼠标指针(在模拟器上)或手指(在设备上),它就会反弹回列表的顶部

我尝试添加AutoResizingMark代码,如中所述,但对我无效


那么,如何修复上述代码,使我的表在尝试滚动时保持滚动状态呢?

嗯,问题似乎与secondVC是从NIB文件创建的,而不是以编程方式创建的有关。我试着这样做:

-(void)littleButtonClicked:(id)sender {
    SecondPopupVC * secondVC=[[SecondPopupVC alloc] init];
    CGSize contentSize = CGSizeMake(320, 320);
    UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 
            contentSize.width, contentSize.height)];
    popoverView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | 
                                    UIViewAutoresizingFlexibleHeight);
    UITableView *tblView = [[UITableView alloc]initWithFrame:popoverView.bounds];
    tblView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | 
                                UIViewAutoresizingFlexibleHeight);

    tblView.delegate = secondVC;
    tblView.dataSource = secondVC;
    tblView.rowHeight = 44;

    [popoverView addSubview:tblView];
    secondVC.view = popoverView;
    secondVC.contentSizeForViewInPopover = contentSize;
    secondVC.stuffInList=self.stuffInList;
    [self.navigationController pushViewController:secondVC animated:YES];
    [secondVC release];
}

你猜怎么着?它很好用。那么,当SecondPopupVC是从NIB文件而不是使用代码初始化时,为什么会出现这样的问题呢?

试试
[secondVC.view setFrame:CGRectMake(0,0320340)]
after
SecondPopupVC.stuffInList=self.stuffInList谢谢,但那不行。还是有同样的问题。我甚至尝试将secondVC.view.autoresizingMask=(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)与setFrame一起添加,但也没有成功。