在xcode中查找数组中数组的长度

时间:2013-09-11 07:44:32

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

在.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);

在选择tablecell时,我尝试在'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];

}

使我的应用程序崩溃的问题是,找到“位置”长度,错误如下:' - [__ NSArrayM长度]:无法识别的选择器发送到实例0x717e8e0'

任何人都可以帮助我。

1 个答案:

答案 0 :(得分:1)

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

- (int) count;

长度仅适用于NSString