故事板中的 UITableView

Posted

技术标签:

【中文标题】故事板中的 UITableView【英文标题】:UITableView in a Storyboard 【发布时间】:2012-11-21 09:28:30 【问题描述】:

你好 *** 的家伙!

我遇到了一个问题,我不知道如何解决它...

我有一个带有 UINavigationController 的 StoryBoard,它有一个 UIViewController 作为 RootViewController。在这个 RootViewController 中,我有 2 个 UIButton。

第一个 UIButton instantiateViewControllerWithIdentifier 一个 UICollectionViewController 很好用。

第二个 UIButton instantiateViewControllerWithIdentifier 一个 UIViewController,它有 2 个 UITableView。这是我实例化 UIViewController 时的问题,我的 2 UITableView 加载良好,但是当我触摸它(滚动)时出现此错误:

-[__NSCFType scrollViewDidScroll:]: unrecognized selector sent to instance 0x752ff90
2012-11-21 10:22:49.300 Month[19992:11303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType scrollViewDidScroll:]: unrecognized selector sent to instance 0x752ff90'

但是当我把它做成 RootViewController 时,一切都如我所愿......所以只有当 RootViewController 实例化我的 UIViewController 时,我才会崩溃。

这就是我在按下 UIButton 时实例化 UIViewController 的方式:

  DayViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"calendarDay"];

希望您能帮助我了解这些信息。

问候,

【问题讨论】:

【参考方案1】:

看起来您有一个对象正在用作UIScrollViewDelegate,并且该对象被释放得太早了。 ([__NSCFType scrollViewDidScroll:] 表示消息正在发送到 Core Foundation 项目,这可能意味着对象地址正在被重用于其他东西。)

您显示的用于创建DayViewController 的代码会将对象分配给一个局部变量。假设您使用的是 ARC,如果这是用作委托的对象,请尝试将其分配给强属性。如:

// .h file
@property (nonatomic, strong) DayViewController *viewController;

// .m file
self.viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"calendarDay"];

【讨论】:

是的!谢谢 !! ARC Gniiiiaa!

以上是关于故事板中的 UITableView的主要内容,如果未能解决你的问题,请参考以下文章

为啥故事板中的按钮不在 ios8 中的适当位置?

故事板中的 UIViewController 容器

使用故事板中的自动布局使 UIButtons 居中

故事板中 tableviewController 中的原型 tableview 单元格

未反映在本地化故事板中的基本故事板更改

故事板中的元素何时创建?