小编Fri*_*Guy的帖子

可重新排序的UITableView,每行最大行数

我是iPhone开发和编程的新手,最近完成了Stephen Kochan的Objective-C 2.0编程,以及Erica Sadun的iPhone Cookbook的部分内容.只是阅读本网站上已回答的问题对我有很大帮助,所以我非常感谢所有用户.现在我正在开发我的第一个iPhone应用程序,并且取得了很好的进展,除了一件令我难过的事情.

我在使用UITableView时遇到了一些麻烦.基本上,我有一个表,每个部分最多需要6行,没有最小值(除非删除1行部分的行,在这种情况下该部分与它一起).该表也可以由用户重新排序.当用户将一行拖动到已经具有最多6个分配行的部分时,我希望该部分的底部行向下排序,以便成为下一部分的顶行.

至于实现这个,我的第一个想法是调用一个方法tableView:moveRowAtIndexPath:toIndexPath:,它将遍历循环中的各个部分,确保它们都没有7行以上,根据需要调整数组,然后使用[myTable beginUpdates]块删除和插入所需的行.这就是所有看起来的样子(注意:我的数组结构是:Array(Table)> Arrays(Sections)> Dictionaries(Items)):

-(void) tableView: (UITableView *) tableView moveRowAtIndexPath: (NSIndexPath *) from toIndexPath: (NSIndexPath *) to
{ 
// Get the dictionary object for the icon.
NSMutableDictionary *theIcon = [[[TABLE_ARRAY_MACRO objectAtIndex: from.section] objectAtIndex: from.row] mutableCopy];

// Now remove it from the old position, and insert it in the new one.
[[TABLE_ARRAY_MACRO objectAtIndex: from.section] removeObjectAtIndex: from.row];
[[TABLE_ARRAY_MACRO objectAtIndex: to.section] insertObject: theIcon atIndex: to.row];

if ( [[TABLE_ARRAY_MACRO objectAtIndex: to.section] count] > 6 …
Run Code Online (Sandbox Code Playgroud)

iphone cocoa-touch objective-c uitableview

6
推荐指数
1
解决办法
1234
查看次数

标签 统计

cocoa-touch ×1

iphone ×1

objective-c ×1

uitableview ×1