【问题标题】:Finding length of the array within the array in xcode在xcode中查找数组中数组的长度
【发布时间】:2013-09-11 07:44:32
【问题描述】:

在.h文件中,

NSString *deal_desc,*terms_cond,*merchant_desc,*locationaddress,*locationcity,*locationstate;

试图找到'detailarray'的长度,以便它可以帮助我分配表格中单元格的高度。

deal_desc = @"sadsad dsa dsad dsad sadsa dsad sadsad adsad sadsad adssad sad adsad sada";
terms_cond = @"sadsad adssa sad asdsad&nbsp";
merchant_desc = @"merchant description describes in detail about merchants";

locationaddress =@"42, South St";
locationcity = @"San Jose";
locationstate = @"California";

location = [[NSMutableArray alloc]init];
NSLog(@"location is %@ \n",location);
detaildescription = [[NSMutableArray alloc]init];


[location addObject:locationaddress];
[location addObject:locationcity];
[location addObject:locationstate];

[detailarray addObject:deal_desc];
[detailarray addObject:terms_cond];
[detailarray addObject:location];
[detailarray addObject:merchant_desc];
NSLog(@"detailarray values are %@ \n",detailarray);

在选择表格单元时,我尝试计算'detailarray'中的字符串和数组的长度,这里

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

[tableView deselectRowAtIndexPath:indexPath animated:YES];
[self.tableview beginUpdates];
id1=indexPath.row;
size = [ detailarray[id1] length];
NSLog(@"size of detaildesc is %d \n",size);
 [self.tableview endUpdates];
[tableview reloadData];

}

导致我的应用崩溃的问题是,找到'location'长度,错误如下:'-[__NSArrayM length]: unrecognized selector sent to instance 0x717e8e0'

谁能在这方面帮助我。

【问题讨论】:

  • 查看NSArray Class Reference 以查看可能使用的成员的完整列表。长度不是其中之一。
  • @Jeremy,你们检查一下....

标签: objective-c arrays nsmutablearray string-length row-height


【解决方案1】:

检查 NSMutableArray 大小的正确函数是:

- (int) count;

长度仅适用于 NSString

【讨论】:

  • 如果你想继续使用NSMutableArray没有其他解决方案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-04
  • 1970-01-01
  • 1970-01-01
  • 2011-05-10
  • 2011-07-16
  • 2022-01-10
相关资源
最近更新 更多