【问题标题】:NSMutableArray have restriction in adding object?NSMutableArray 添加对象有限制吗?
【发布时间】:2016-03-21 10:10:51
【问题描述】:

我使用NSMutableArray 添加对象。但它只添加前 10 个对象。 我有分享代码

  for (int j = 0; j<[feedData count]; j++)
    {

       [sharingItems addObject:[self whatsappdata:[feedData objectAtIndex:j]]];

    }

这个方法返回NSString输入文字。

请为此提供有效的解决方案。

提前致谢

      -(NSString *)whatsappdata:(NSDictionary *)cellData1
      {

NSString *brandName = [NSString stringWithFormat:@"%@", [cellData1 objectForKey:@"brand_name"]];
NSString *modelName = [NSString stringWithFormat:@"%@", [cellData1 objectForKey:@"brand_model_name"]];

NSString *version = [NSString stringWithFormat:@"%@", [cellData1 objectForKey:@"version_name"]];
if ([version  isEqualToString: @"<null>"])
{
    version = @"";
}
NSString *year = [NSString stringWithFormat:@"%@", [cellData1 objectForKey:@"model_year"]];
if (year == nil || [year isEqualToString:@"0"])
{
    year = @"";
}
NSString *inventoryValue = [NSString stringWithFormat:@"%@",[cellData1 objectForKey:@"inventory_type"]];
NSInteger value = [inventoryValue intValue];
NSString *inventoryName;
NSString *msg;
if(value == 1)
{
    inventoryName = [NSString stringWithFormat:@"%@", @"Stock"];
    i++;
    NSString *text2 = [NSString stringWithFormat:@"%d.%@ %@ %@- %@ Single Owner\n",i, brandName, modelName, version, year];
    msg = [NSString stringWithFormat:@"%@",text2];
    msg= [msg  stringByReplacingOccurrencesOfString:@"\n" withString:@"<br/>"];
}
else
{
    inventoryName = [NSString stringWithFormat:@"%@", @"Required"];
    msg = @"";
}



return msg;
//end data

   }

【问题讨论】:

  • 可以分享初始化数组的代码吗?
  • sharingItems = [[NSMutableArray alloc]init];
  • feedData 的计数是多少?
  • 尝试简单地添加一个 NSString 到 sharedItems 以排除 whatsappdata: 方法中的一些奇怪的东西。 feedData 的计数是多少?您是否在代码中的其他任何地方使用了sharingItems?
  • 使用调试器单步调试您的代码。正如 Piyush 已经问过的,feedData 中实际上有多少项目?也就是说,[feedData count] 的值是多少?问题一定是您只将 10 个项目放入数组中,因为 NSMutableArray 没有限制。

标签: ios objective-c iphone xcode nsmutablearray


【解决方案1】:

很可能“获取限制”已在您的代码中设置为“NSFetchRequest”。

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; 
[fetchRequest setFetchLimit:10];//such code you need to find and remove/change fetch limit

【讨论】:

    【解决方案2】:

    你需要在添加元素之前为数组分配内存

    sharingItems = [[NSMutableArray alloc]init];
    

    【讨论】:

      猜你喜欢
      • 2011-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-09
      • 2012-01-25
      • 1970-01-01
      相关资源
      最近更新 更多