【问题标题】:Detect length of NSMutableArray检测 NSMutableArray 的长度
【发布时间】:2014-02-03 03:32:43
【问题描述】:

我对如何解决这个问题感到有些不知所措,但我的搜索却一无所获。

我有以下代码:

- (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 从一个 group 重新订购到另一个 UITableViewController

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

NSMutableArray 的大小发生变化时,我需要检查运行时,因为我将row 从一个section 移动到另一个。 有人可以帮帮我吗:-)

【问题讨论】:

  • 何时在可变数组中添加或删除项目?你不控制吗?当项目改变时你能更新你的表吗?
  • 是的,@AaronBrager 的意思是,你怎么能知道,因为 是做出改变的人。
  • mmm 好的 - 不是我不知道,我的意思是就控制器而言要做什么来理解它,然后我想知道它是否在正确的位置应用程序的流量。 - 我会更新评论:-)

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


【解决方案1】:

您正在尝试将 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];
}

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

【讨论】:

  • 我使用的是分组布局,所以有 2 个部分 - 您给出的答案仍然崩溃,但正在尝试找出原因。
猜你喜欢
  • 2018-05-01
  • 1970-01-01
  • 2014-05-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-13
  • 2010-11-14
相关资源
最近更新 更多