【问题标题】:Remove all items from array and repopulate it从数组中删除所有项目并重新填充它
【发布时间】:2015-09-03 20:54:47
【问题描述】:

我有这个数组:

NSArray *currentPath;

它被填充在这里:

currentPath = [[[self.tableData objectAtIndex:indexPath.row] objectForKey:@"Name"] componentsSeparatedByString:@"FTP\\"];

我需要重新填充这个数组

NSString *newPreviousPath = [previousPath stringByReplacingOccurrencesOfString:nextItemToRemoveString withString:@""];

    currentPath = [newPreviousPath];

但我不断收到此错误:

Expected identifier

我该如何解决这个问题并完成这个?

【问题讨论】:

  • 整个错误是什么?粘贴所有代码?

标签: objective-c arrays


【解决方案1】:

与 swift 不同,在目标 c 中你应该这样做:

currentPath = @[newPreviousPath];

看看@符号在Objective C中的作用,详细答案在这里:Is there some literal dictionary or array syntax in Objective-C?

【讨论】:

    【解决方案2】:

    currentPath = [newPreviousPath]; 在这里,您使用的是 Literals 语法,这不是分配数组的正确方法。您需要执行以下操作 currentPath = @[newPreviousPath];

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-29
      • 2013-03-27
      • 2012-02-29
      • 1970-01-01
      • 1970-01-01
      • 2020-12-28
      • 2011-06-19
      • 1970-01-01
      相关资源
      最近更新 更多