popup窗口中的UITableView不会滚动

我正试图解决某人的代码,并遇到一个问题。 这是情况:我有一个全屏UIViewController有一个底部的栏button。 当我按下该button时,它会在屏幕左下angular显示一个popup视图控制器。 popup窗口中的视图控制器也有一个button,当我按THATbutton时,它将一个新的视图控制器到我的popup窗口。 这个新的视图控制器是一个UITableView,可以有大量的元素。 问题是,当我尝试向下滚动以查看一些离屏元素时,滚动会弹回到表中的第一个位置,即它不会真的滚动。

更具体的是这里是一些代码:

在FullScreenVC.h中:

@property (nonatomic, retain) NSMutableArray* stuffInList; @property (nonatomic, retain) UIPopoverController *namePopover; @property (nonatomic, retain) UINavigationController *nameNav; @property (nonatomic, retain) UIBarButtonItem* addButton; 

内FullScreenVC buttonPressed(按下addButton时调用):

 FirstPopupVC *vc=[FirstPopupVC alloc] initWithNibName@"FirstPopupVC" bundle:nil]; vc.delegate=self; vc.stuffInList=self.stuffInList; // This is just the NSArray of list items self.nameNav = [[[UINavigationController alloc] initWithRootViewController:vc] autorelease]; self.namePopover = [[[UIPopoverController alloc] initWithContentViewController:self.nameNav] autorelease]; [vc release]; [self.namePopover presentPopoverFromBarButtonItem:self.addButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 

换句话说,FirstPopupVC对象vc是UINavigationViewController nameNav的根视图控制器,nameNav是namePopover UIPopoverController中的内容的导航控制器。 我认为最后一行启动FirstPopupVC作为从addButtonpopup。 还要注意,XIB文件FirstPopupVC.xib是一个简单的NIB文件,它具有一些简单的视图(标签等)和一个用户可以按下来获得第二个popup窗口的小button,我们将会看到。

在FirstPopupVC里面我们有:

 - (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]; } 

这当然提出了popop中的第二个视图控制器。

在SecondPopupVC里面我们有:

 - (id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { self.contentSizeForViewInPopover = CGSizeMake(320, 340); } return self; } 

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

所以问题是,如果我的listOfStuff很大,也就是说,如果表中的项目集合很大,那么表格将不会保持滚动,超出第一个可见的行集合。 我可以向下滚动查看这些项目,但只要释放鼠标指针(在模拟器上)或我的手指(在设备上),它就会弹回到列表顶部。

我试图添加autoresizingmak代码,如表中所讨论的popover 不滚动,但这并不适用于我。

那么我怎样才能修正上面的代码,让我的表格在滚动的时候保持滚动?

那么,这似乎是问题有关的事实,secondVC是从一个NIB文件而不是编程创build的。 我尝试这样做,而不是:

 -(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文件初始化而不是使用代码时会出现这样的问题呢?