检测NSMutableArray的长度

时间:2014-02-03 03:32:43

标签: ios objective-c cocoa-touch uitableview nsmutablearray

我对如何解决这个问题感到有点愚蠢,而且我的搜索无法进入任何地方。

我有以下代码:

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
  [_testTableView beginUpdates];

  NSDictionary *dictionary = [_array00 objectAtIndex:fromIndexPath.section];
  NSMutableArray *array = [dictionary objectForKey:@"data"];

  NSString *itemToMove = [array objectAtIndex:fromIndexPath.row];
  [array removeObjectAtIndex:fromIndexPath.row];
  [array insertObject:itemToMove atIndex:toIndexPath.row];

  [_testTableView moveSection:fromIndexPath.section toSection:toIndexPath.section];

    //I need to know what size my array is at this point. _array00 is a NSMutableArray made up from 2 other NSMutableArrays.

  [_testTableView endUpdates];

}

因此,我正在制作一款应用,允许您在cells中将groupUITableViewController重新排序到另一个{。}}。

我不确定我是否会说得对,但我希望这是有道理的。

我需要在NSMutableArray的大小发生变化时检查运行时,因为我将rowsection移到另一个{{1}}。 有人可以帮帮我: - )

1 个答案:

答案 0 :(得分:0)

您正在尝试将itemToMove添加到同一部分。将itemToMove添加到toindexpath.section数组..

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
[_testTableView beginUpdates];

NSDictionary *dictionary = [_array00 objectAtIndex:fromIndexPath.section];
NSMutableArray *array = [dictionary objectForKey:@"data"];

NSString *itemToMove = [array objectAtIndex:fromIndexPath.row];
  [array removeObjectAtIndex:fromIndexPath.row];

NSDictionary *toDictionary = [_array00 objectAtIndex:toIndexPath.section];
NSMutableArray *toArray = [toDictionary objectForKey:@"data"];
  [toArray insertObject:itemToMove atIndex:toIndexPath.row];

[_testTableView moveSection:fromIndexPath.section toSection:toIndexPath.section];

//This is where I assume my missing code has to go

  [_testTableView endUpdates];
}

我希望这可以解决你的问题..