弹出式窗口中的UITableView将不会滚动 [英] UITableView inside popover will not scroll

查看:90
本文介绍了弹出式窗口中的UITableView将不会滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to fix someone's code and am running into a problem. Here is the situation: I have a full screen UIViewController that has a bottom bar button. When I press that button, it shows a popup view controller in the bottom left of the screen. That view controller inside the popup also has a button, and when I press THAT button it pushes a new view controller into my popup window. That new view controller is a UITableView that can have some large number of elements. The problem is that when I try to scroll down to see some offscreen elements, the scroll bounces back to the first position in the table, i.e. it does not really scroll.

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

More specifically here is some code:

在FullScreenVC.h中:

In 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时调用):

Inside FullScreenVC buttonPressed (called when addButton is pressed):

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内部的内容.我认为最后一行是从addButton弹出的窗口中启动FirstPopupVC的.还要注意,XIB文件FirstPopupVC.xib是一个简单的NIB文件,它具有一些简单的视图(标签等)和一个用户可以按下以获取第二个弹出窗口的小按钮.

In other words, the FirstPopupVC object vc is the root view controller of a UINavigationViewController nameNav, and nameNav is the navigationcontroller that is the content inside the namePopover UIPopoverController. I think the last line launches FirstPopupVC as a popup from the addButton. Note also that the XIB file FirstPopupVC.xib is a simple NIB file that has a few simple views (label etc) and a little button that a user can press to get the second popup, as we'll see.

在FirstPopupVC内部,我们有:

Inside FirstPopupVC we have:

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

这当然是弹出框内的第二个视图控制器.

This of course presents the second view controller inside the popop.

在SecondPopupVC内部,我们有:

Inside SecondPopupVC we have:

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

    }
    return self;
}

显然,这里的contentSizeForViewInPopover调用将使用表视图设置弹出视图的大小.看起来这在第一个和第二个视图控制器中都在initWithNibName内部被调用.

Apparently the contentSizeForViewInPopover call here will set the size of the popover view with the table view. It looks like this is called inside initWithNibName in both the first and second view controllers.

同样,问题是如果我的listOfStuff很大,即表中的项目集很大,那么该表将不会滚动到第一个可见行集合之外.我可以向下滚动以查看这些项目,但是一旦松开鼠标指针(在模拟器上)或手指(在设备上),它就会弹回到列表的顶部.

So again, the problem is that if my listOfStuff is large, ie if the set of items in the table is large, then the table will not stay scrolled beyond the first visible set of rows. I can scroll down to see these items but as soon as I release the mouse pointer (on the emulator) or my finger (on the device), it bounces back to the top of the list.

我尝试添加自动调整大小的mak代码,如弹出窗口中的表格视图中所述滚动,但这对我不起作用.

I tried to add autoresizingmak code as discussed in table view in popover is not scrolling but that didn't work for me.

那么我该如何解决上面的代码,以便当我尝试滚动表格时表格保持滚动状态?

So how can I fix the above code so that my table stays scrolled when I try to scroll it?

推荐答案

好吧,问题似乎与secondVC是从NIB文件而不是通过编程创建的事实有关.我尝试这样做:

Well, it appears that the problem has something to do with the fact that secondVC is created from a NIB file rather than programmatically. I tried doing this instead:

-(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时会出现这样的问题呢?

and guess what? It works fine. So why would there be such a problem when SecondPopupVC is initialized from a NIB file rather than using code?

这篇关于弹出式窗口中的UITableView将不会滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆