【问题标题】:My UINavBar doesn't Respond to Touch, and Scrolls with tableview我的 UINavBar 不响应触摸,并使用 tableview 滚动
【发布时间】:2012-07-28 03:33:36
【问题描述】:

我有一个 UITableViewController 的子类,我想向它添加一个 UINavBar。这是一个与本地联系人应用程序非常相似的设置,您可以在其中点击“添加联系人”,它会显示一个分组的表格视图,顶部有一个导航栏,带有“取消”和“完成”选项。关键是我需要它使用垂直过渡来呈现(有效地使用 presentModalViewController:animated:yes),但我尝试使用 Interface Builder 并以编程方式添加它,在这两种情况下,按钮都没有响应,并且栏滚动使用 tableview,而不是停留在顶部。

提前致谢,

哈尔加瓦

【问题讨论】:

  • 发布您的代码会有很大帮助。

标签: objective-c ios uinavigationcontroller uitableview


【解决方案1】:

听起来您正在使导航栏成为表格视图的子视图,这解释了为什么导航栏会随着表格视图滚动。

在action方法中试试这个:

MyTableViewController *table = [MyTableViewController alloc] initWithStyle:UITableViewStyledGrouped];
UINavigationController *nav = [UINavigationController alloc] initWithRootViewController:table];

[self presentModalViewController:nav animated:YES];

然后在你的表视图控制器的viewDidLoad:

UIBarButtonItem *doneButton = [UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(done:)];
self.navigationItem.rightBarButtonItem = doneButton;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-03
    • 1970-01-01
    • 2021-10-31
    相关资源
    最近更新 更多