表视图不会响应

发布于 2024-11-01 15:55:01 字数 3788 浏览 3 评论 0原文

我有一个派生自 UITableViewController 的 BarTableViewController 。 这是我的主视图,因此在应用程序启动时会自动加载,并且该类的实例运行良好。

现在我试图让原始实例推送同一个类的另一个实例,如下所示:

BarTableViewController *bar = [[[BarViewController alloc] initForFoo:theFoo] autorelease];
[self.navigationController pushViewController:bar animated:YES];

initForFoo 方法如下所示:

- (id)initForFoo:(Foo *)theFoo
{
    if ((self = [self initWithNibName:@"BarTableViewController" bundle:nil])) {
        self.foo = theFoo;
    }
    return self;
}

推送有效,视图加载,并且在模拟器中工作正常。

然而,在我的 iPhone 4 上,表格视图在第二种情况下没有响应:我的手指在屏幕上上下滑动没有任何反应。如果我点击搜索栏,然后点击取消,表格就会变得响应式。

如果我只是调用 init 而不是 if initWithNibName 那么表视图即使第一次也会正确响应,但当然我的 IBOutlet 内容都没有被绑定。

这似乎是一次性的事情:一旦我完成了搜索并取消,表格就会响应,即使我点击后退按钮然后再次回到视图控制器的同一个实例,它也会赢不要被卡住。

我在这里做错了什么?

更新: 我在 MainWindow.xib 中确实有这个家伙作为 RootViewController。我试着接受那个 并让应用程序委托创建他,但行为仍然相同:一切 除了表格视图不滚动之外,都可以工作。但现在初始实例也被冻结了。

因此,每当我显式调用 initWithNibName 时,我都会得到这种冻结的行为。

更新2: 我一直在注释掉 viewDidLoad 的不同块,如果我忽略这一点,它似乎总是有效:

[self.navigationController setToolbarHidden:NO animated:NO];

当然,这意味着我没有工具栏。我尝试将其放回原处,但没有工具栏项目,但仍然存在问题。

更新3: 在处于这种状态时使用 GDB,这就是我在 UITableView 中找到的内容:

(gdb) p * [[[UIApplication sharedApplication] delegate] searchViewController]
  <UITableViewController> = {
    <UIViewController> = {
      <UIResponder> = {
        <NSObject> = {
          isa = 0x9fe44
        }, <No data fields>}, 
      members of UIViewController: 
      _view = 0xa27600, 
      _tabBarItem = 0x0, 
      _navigationItem = 0x4d6dcc0, 
      _toolbarItems = 0x0, 
      _title = 0x0, 
      _nibName = 0xb9120, 
      _nibBundle = 0x242b40, 
      _parentViewController = 0x4d6de90, 
      _childViewControllers = 0x0, 
      _childModalViewController = 0x0, 
      _parentModalViewController = 0x0, 
      _modalTransitionView = 0x0, 
      _modalPreservedFirstResponder = 0x0, 
      _defaultFirstResponder = 0x0, 
      _dimmingView = 0x0, 
      _dropShadowView = 0x0, 
      _presentationSuperview = 0x0, 
      _sheetView = 0x0, 
      _currentAction = 0x0, 
      _savedHeaderSuperview = 0x0, 
      _savedFooterSuperview = 0x0, 
      _editButtonItem = 0x0, 
      _searchDisplayController = 0x4d7b290, 
      _popoverController = 0x0, 
      _modalTransitionStyle = UIModalTransitionStyleCoverVertical, 
      _modalPresentationStyle = UIModalPresentationFullScreen, 
      _lastKnownInterfaceOrientation = UIInterfaceOrientationPortrait, 
      _contentSizeForViewInPopover = {
        width = 320, 
        height = 1100
      }, 
      _formSheetSize = {
        width = 0, 
        height = 0
      }, 
      _viewControllerFlags = {
        appearState = 2, 
        isEditing = 0, 
        isPerformingModalTransition = 0, 
        hidesBottomBarWhenPushed = 0, 
        autoresizesArchivedViewToFullSize = 0, 
        viewLoadedFromControllerNib = 0, 
        isRootViewController = 0, 
        isSheet = 0, 
        isSuspended = 0, 
        wasApplicationFrameAtSuspend = 0, 
        wantsFullScreenLayout = 0, 
        shouldUseFullScreenLayout = 0, 
        allowsAutorotation = 1, 
        searchControllerRetained = 1, 
        oldModalInPopover = 0, 
        isModalInPopover = 0, 
        restoreDeepestFirstResponder = 0, 
        isInWillRotateCallback = 0, 
        disallowMixedOrientationPresentations = 0, 
        modalPresentationsAreCurrentContext = 0
      }
    }, 
    members of UITableViewController: 
    _tableViewStyle = UITableViewStylePlain, 
    _keyboardSupport = 0x4d87540, 
    _tableViewControllerFlags = {
      clearsSelectionOnViewWillAppear = -1
    }
  }, 

我在 gdb 中尝试了一些盲目的 isFirstResponder 刺探,但没有运气。

I have a BarTableViewController that derives from UITableViewController.
It's my main view and so is loaded automatically when the app starts, and that instance of the class works fine.

Now I am trying to have that original instance push another instance of the same class like this:

BarTableViewController *bar = [[[BarViewController alloc] initForFoo:theFoo] autorelease];
[self.navigationController pushViewController:bar animated:YES];

The initForFoo method looks like this:

- (id)initForFoo:(Foo *)theFoo
{
    if ((self = [self initWithNibName:@"BarTableViewController" bundle:nil])) {
        self.foo = theFoo;
    }
    return self;
}

The push works and the view loads, and works fine in the simulator.

However on my iPhone 4 the table view is not responsive in this second instance: sliding my finger up and down the screen does nothing. If I tap in the search bar then tap cancel, the table then becomes responsive.

If I just call init instead if initWithNibName then the table view responds correctly even the first time, but of course none of my IBOutlet stuff gets bound.

This appears to be a one-time only thing: once I've done the search-and-cancel the table will respond, and even if I hit the back button then come back to this same instance of the view controller again, it won't get stuck.

What am I doing wrong here?

UPDATE:
I did have this guy as RootViewController in my MainWindow.xib. I tried taking that
out and making the app delegate create him, but still same behavior: everything
works except for the table view not scrolling. But now the initial instance also is frozen.

So, whenever I explicitly called initWithNibName I get this frozen behavior.

UPDATE2:
I've been commenting out different chunks of viewDidLoad and it seems to work all the time if I omit this:

[self.navigationController setToolbarHidden:NO animated:NO];

Of course that means I get no toolbar. I've tried putting it back in with no toolbar items, and it still exhibits the problem.

UPDATE3:
Breaking in with GDB while it's in this state, this is what I find in the UITableView:

(gdb) p * [[[UIApplication sharedApplication] delegate] searchViewController]
  <UITableViewController> = {
    <UIViewController> = {
      <UIResponder> = {
        <NSObject> = {
          isa = 0x9fe44
        }, <No data fields>}, 
      members of UIViewController: 
      _view = 0xa27600, 
      _tabBarItem = 0x0, 
      _navigationItem = 0x4d6dcc0, 
      _toolbarItems = 0x0, 
      _title = 0x0, 
      _nibName = 0xb9120, 
      _nibBundle = 0x242b40, 
      _parentViewController = 0x4d6de90, 
      _childViewControllers = 0x0, 
      _childModalViewController = 0x0, 
      _parentModalViewController = 0x0, 
      _modalTransitionView = 0x0, 
      _modalPreservedFirstResponder = 0x0, 
      _defaultFirstResponder = 0x0, 
      _dimmingView = 0x0, 
      _dropShadowView = 0x0, 
      _presentationSuperview = 0x0, 
      _sheetView = 0x0, 
      _currentAction = 0x0, 
      _savedHeaderSuperview = 0x0, 
      _savedFooterSuperview = 0x0, 
      _editButtonItem = 0x0, 
      _searchDisplayController = 0x4d7b290, 
      _popoverController = 0x0, 
      _modalTransitionStyle = UIModalTransitionStyleCoverVertical, 
      _modalPresentationStyle = UIModalPresentationFullScreen, 
      _lastKnownInterfaceOrientation = UIInterfaceOrientationPortrait, 
      _contentSizeForViewInPopover = {
        width = 320, 
        height = 1100
      }, 
      _formSheetSize = {
        width = 0, 
        height = 0
      }, 
      _viewControllerFlags = {
        appearState = 2, 
        isEditing = 0, 
        isPerformingModalTransition = 0, 
        hidesBottomBarWhenPushed = 0, 
        autoresizesArchivedViewToFullSize = 0, 
        viewLoadedFromControllerNib = 0, 
        isRootViewController = 0, 
        isSheet = 0, 
        isSuspended = 0, 
        wasApplicationFrameAtSuspend = 0, 
        wantsFullScreenLayout = 0, 
        shouldUseFullScreenLayout = 0, 
        allowsAutorotation = 1, 
        searchControllerRetained = 1, 
        oldModalInPopover = 0, 
        isModalInPopover = 0, 
        restoreDeepestFirstResponder = 0, 
        isInWillRotateCallback = 0, 
        disallowMixedOrientationPresentations = 0, 
        modalPresentationsAreCurrentContext = 0
      }
    }, 
    members of UITableViewController: 
    _tableViewStyle = UITableViewStylePlain, 
    _keyboardSupport = 0x4d87540, 
    _tableViewControllerFlags = {
      clearsSelectionOnViewWillAppear = -1
    }
  }, 

I've tried a few blind isFirstResponder stabs in gdb with no luck.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

短暂陪伴 2024-11-08 15:55:01

我读到:

如果您在同一个 NIB 中创建视图控制器及其视图,并将视图嵌套在视图控制器下方,它将自动调整视图的框架。

这个问题的答案中,这激励我尝试编辑我的 XIB 并添加 ViewController 和将 TableView 放在其下 - 以前我必须将 ViewController 放在 XIB 中,而 TableView 位于顶层。

这解决了我的“冻结表格视图”问题,但我仍然不明白为什么:我对各个组件的框架尺寸进行了一系列前后检查,但无法判断发生了什么变化。但它已经修复了至少。

I read:

If you create your view controller and its view in the same NIB, and you nest the view underneath the view controller, it will adjust the view's frame automatically.

in an answer to this question and this inspired me to try editing my XIB and adding a ViewController and putting the TableView under that—previously I had to ViewController in the XIB and TableView was at the top level.

This fixes my "frozen table view' issue, but I still don't really understand why: I did a bunch of before-and-after examining of frame sizes of the various components and couldn't tell what had changed. But it's fixed at least.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文