弹出窗口内的UITableView不会滚动

时间:2013-11-26 00:57:10

标签: ios uitableview scroll uipopovercontroller uipopover

我正在尝试修复某人的代码并遇到问题。情况如下: 我有一个全屏UIViewController,有一个底部按钮。当我按下该按钮时,它会在屏幕的左下方显示一个弹出视图控制器。弹出窗口中的视图控制器也有一个按钮,当我按下THAT按钮时,它会将一个新的视图控制器推入我的弹出窗口。新的视图控制器是一个可以拥有大量元素的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时调用):

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是navigationPoot,它是namePopover UIPopoverController中的内容。我认为最后一行是从addButton启动FirstPopupVC作为弹出窗口。另请注意,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];
}

这当然会在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调用将使用表视图设置弹出窗口视图的大小。看起来这在第一个和第二个视图控制器中都在initWithNibName内调用。

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

我试图添加autoresizingmak代码,如table view in popover is not scrolling中所述,但这对我不起作用。

那么如何修复上面的代码,以便在我尝试滚动时我的表格保持滚动状态?

1 个答案:

答案 0 :(得分:0)

好吧,问题似乎与second NC是从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];
}

并猜猜是什么?它工作正常。那么,为什么在从NIB文件初始化SecondPopupVC而不是使用代码时会出现这样的问题?

相关问题