【发布时间】:2013-11-26 11:32:21
【问题描述】:
我正在尝试修复某人的代码,但遇到了问题。情况如下: 我有一个带有底部栏按钮的全屏 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 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 作为 addButton 的弹出窗口启动。另请注意,XIB 文件 FirstPopupVC.xib 是一个简单的 NIB 文件,它有一些简单的视图(标签等)和一个小按钮,用户可以按下该按钮来获得第二个弹出窗口,我们将看到。
在 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];
}
这当然是在弹出窗口中展示第二个视图控制器。
在 SecondPopupVC 里面我们有:
- (id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.contentSizeForViewInPopover = CGSizeMake(320, 340);
}
return self;
}
显然这里的 contentSizeForViewInPopover 调用将设置弹出视图与表格视图的大小。看起来这在第一个和第二个视图控制器的 initWithNibName 中都被调用了。
同样,问题是如果我的 listOfStuff 很大,即如果表中的项目集很大,那么表将不会保持滚动超过第一个可见的行集。我可以向下滚动查看这些项目,但只要我松开鼠标指针(在模拟器上)或我的手指(在设备上),它就会弹回列表顶部。
我尝试添加 table view in popover is not scrolling 中讨论的 autoresizingmak 代码,但这对我不起作用。
那么我怎样才能修复上面的代码,让我的表格在我尝试滚动时保持滚动?
【问题讨论】:
-
在
SecondPopupVC.stuffInList=self.stuffInList;之后尝试[secondVC.view setFrame:CGRectMake(0,0,320,340)]; -
谢谢,但这不起作用。仍然有同样的问题。我什至尝试将 secondVC.view.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight) 与 setFrame 一起添加,但也没有用。
标签: ios uitableview scroll uipopovercontroller uipopover