如何划分数组并在表格视图中显示?
我正在开发一个表格视图。为了填充该表,我有一个包含 75 个内容的数组。现在我想显示表视图,就像第一次显示表视图时一样,然后只显示 10 行数组和一个标题为“显示更多”的按钮。当单击按钮时,然后在表视图中显示数组的下 10 个内容,并在表视图的最后一个中显示上一个和下一个两个按钮。当单击“下一个”时,将再次显示数组的下 10 个内容;当单击“上一个”时,将显示前 10 个内容。现在的问题是我将如何处理数组才能获得这种类型的外观?如何在表视图中编写代码?
I am developing a table view. To fill that table i have an array of 75 content. Now i want to show table view like as when first time shown table view then show only 10 row of array and one button whose title is show more. when click on button then show next 10 content of array in table view and in last of table view show two button previous and next. When click on next then again show next 10 content of array and when click on previous then show previous 10 content. Now problem is that what i will do with array so that i get this type look? How code for that in table view?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以像下面这样..
1.. 假设 n=11 取一个变量
2.. 在
cellForRowAtIndexPath
中只为 n-1 个单元格编写代码... nth 单元格第一次创建一个按钮,显示 显示更多 正如你所说的3.. 现在在
didSelectRowAtIndexPath
中编写一段代码来标识所选的单元格有索引== ??如果是,则调用一个方法,将 n 加 10,然后再次重新加载表。4.. 根据需要继续递增和递减 n...但请记住使用第 n 行选择重新加载数据
You can go like below..
1.. Take a variable suppose n=11
2.. in
cellForRowAtIndexPath
write a code for only n-1 cells... and for nth cell create a button for first time that shows show more as you said3.. Now in
didSelectRowAtIndexPath
write a code to identify that the selected cell has index == n?? if yes then call a method which will increment n with 10 and then again reload table.4.. Go on incrementing and decrementing n as you want... but remember to reload data with nth row selection
您可以通过以下方式使用按钮的标签属性(uiview 的任何子级继承该属性)来实现此目的。
您可以将数组分为 10 个元素的数组,并将每个元素存储在其他数组中。现在要检索数据,您可以设置按钮的
tag
。也就是说,例如,更多按钮标签最初将为 1。因此,当单击它时,您可以从数组数组中检索第一个数组并显示它,并将更多按钮标记设置为 2。因此,下次更多按钮将导致从大数组中获取第二个元素。同样,前一个将存储相应的标签,您可以使用它来获取前一个数组。现在上面也可以在没有二维数组的情况下完成。为此,您可以将 moreButton.tab 乘以 10 并显示数组的下 10 个元素。
请在更新标签属性之前进行必要的验证检查。
希望有帮助。
You can achieve this using tag property of button(any child of uiview inherits that) in following way.
You can divide array in an arrays of 10 element and store each of them in other array. Now to retrieve data you can set
tag
of the button. That is, for example, more button tag would be 1 initially. so when it is clicked you can retrieve 1st array from array of arrays and show it and set more button tag to 2. thus next time more button will cause fetching of 2nd element from big array. Same way previous will store respective tag and you can use that to fetch previous array.Now above can be done without 2D array also. For that you can multiply moreButton.tab with 10 and display next 10 element of array.
Please put required validation check before updating tag property.
Hope it helps.