可变数组ObjectAtIndexs

时间:2013-07-10 17:43:12

标签: ios objective-c arrays

我正在使用以下代码从NSMutableArray

创建标签
CGRect punti = CGRectMake(270, 200, 50, 50);
CGRect punti2 = CGRectMake(370, 200, 50, 50);
CGRect punti3 = CGRectMake(470, 200, 50, 50);

[_Cordinate3lettere insertObject:[NSMutableArray arrayWithObjects:[NSValue valueWithCGRect:punti],[NSValue valueWithCGRect:punti],[NSValue valueWithCGRect:punti], nil] atIndex:0];

UILabel *label = [[UILabel alloc] init];
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 2)];

// Error occurs on line below
label.frame = [[_Cordinate3lettere objectAtIndexs:indexSet] CGRectValue];
label.text = @"a"; 
label.backgroundColor = [UIColor colorWithWhite:1 alpha:0];
//label.font =
[self.view addSubview:label];

但是,以下行会生成错误。

label.frame = [[_Cordinate3lettere objectAtIndexs:indexSet] CGRectValue];

收到的错误是No visible @interface for NSMutableArray declares the selector "objectAtIndexs"

导致此错误的原因是什么以及如何解决?

2 个答案:

答案 0 :(得分:2)

你的通话中有拼写错误。方法名称是:

- (NSArray *)objectsAtIndexes:(NSIndexSet *)indexes

不是objectAtIndexs

答案 1 :(得分:0)

替换label.frame = [[_Cordinate3lettere objectAtIndexs:indexSet] CGRectValue];

使用:

NSArray *frames = [_Cordinate3lettere objectAtIndexes:indexSet];
label.frame = [[frame objectAtIndex:0 /*or whatever index you want here*/] CGRectValue];