在主/明细应用程序的主视图控制器中动态提供uitableview [英] Issue feeding dynamically the uitableview in the masterview controller of a master/detail app

查看:117
本文介绍了在主/明细应用程序的主视图控制器中动态提供uitableview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在根据主/详细应用模板创建项目后尝试提供主视图的内容。

I am trying to feed the content of a masterview after creating a project based on the master/detail app template.

我基本上有一个内容我所有的模型以后可能会改变的数据。我想通过提供每个部分的行数和具有此模型的部分数量来自动提供tableview的内容。

I have basically a model that content all my data which might change later on. I want to feed automatically the content of the tableview by providing the number of rows per section and number of sections that has this model.

我设法通过覆盖以下2个函数:

I manage to do so by overriding the following 2 functions:

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

我有一个NSRangeException异常,但如果我没有编辑主视图控制器 - 主场景的故事板,使其在部分中反映出比我的模型更多的部分和行。

I got a NSRangeException exception though if i didn't edit the storyboard for the Master View Controller - Master Scene such that it reflects a larger number of sections and rows in sections than my model has.

例如:我离开了故事板主场景有1个部分和1个行。如果我在numberOfRowsInSection函数中返回2,我的程序将在运行时因此NSRangeExceptionError错误而崩溃:

e.g: I left the storyboard for the Master Scene with 1 section and 1 row. If i return 2 in the numberOfRowsInSection function my program will crash at run time with this NSRangeExceptionError error:

2011-10-10 14:38:53.042 sample_project[3636:f803] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]'

*** First throw call stack:

(0x13bb052 0x154cd0a 0x13a7674 0x432805 0x24227a 0x1ed548 0x1ef722 0x9f7c7 0x9f2c1 0xa228c 0xa6783 0x51301 0x13bce72 0x1d6592d 0x1d6f827 0x1cf5fa7 0x1cf7ea6 0x1d8330c 0x114c6 0x11bd6 0x20743 0x211f8 0x14aa9 0x12a5fa9 0x138f1c5 0x12f4022 0x12f290a 0x12f1db4 0x12f1ccb 0x112a7 0x12a9b 0x25e2 0x2555)

terminate called throwing an exceptionsharedlibrary apply-load-rules all

Current language:  auto; currently objective-c

(gdb) 

有没有人看到原因这个行为?我错过了什么吗?我是否需要进行一些额外的初始化,以便在控制器的didLoad函数中为tableview设置默认大小?

Does anyone see a reason for this behavior? Am I missing something? Do I need to make some extra initialization that will set a default size for the tableview in the didLoad function of the controller?

推荐答案

我发现默认的表视图Content属性设置为static。您可以将其更改为动态原型。您需要为单元格提供标识符:我不确定如何使用它。这解决了我上面提到的崩溃。

I found out that the default table view Content attribute is set to static. You can change it to Dynamic Prototypes. You need to provide a identifier for the cell: I am not sure how this is used though. This solved the crash i was mentioning above.

这篇关于在主/明细应用程序的主视图控制器中动态提供uitableview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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