我在这种方法中向NSMutableArray
添加对象:
CarouselObject *objectModel = [[CarouselObject alloc]init];
objectModel.name = [[d objectForKey:@"place"] objectForKey:@"name"];
objectModel.address = [[d objectForKey:@"place"] objectForKey:@"address"];
//cview = [[CaroView alloc] initWithFrame:CGRectMake(x, 0, 320, 170)];
//cview.backgroundColor = [UIColor greenColor];
//cview.images.image = [UIImage imageNamed:@"banner.jpg"];
if ([photo count] > 0) {
NSLog(@"%@",[[photo objectAtIndex:0] objectForKey:@"place_photo_reference"]);
objectModel.imageURL = [NSString stringWithFormat:@"http://www.getnearest.com/api2/google_image.php?photoreference=%@&type=photo", [[photo objectAtIndex:0] objectForKey:@"place_photo_reference"]];
// [cview.images setImageWithURL:[NSURL URLWithString:objectModel.imageURL ] placeholderImage:[UIImage imageNamed:@"banner.jpg"]];
// cview.images.contentMode = UIViewContentModeRedraw;
// cview.name.text = [[d valueForKey:@"place"] objectForKey:@"name"];
// cview.address.text = [[d valueForKey:@"place"] objectForKey:@"address"];
} else if ([photo count] == 0) {
objectModel.imageURL = @"";
}
[carouselArray addObject:objectModel];
// [responseScroll addSubview:cview];
// x += 320;
}
[self updateUI:carouselArray];
//responseScroll.contentSize = CGSizeMake(x, 170);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
}
我需要在此方法中使用数组:
-(void)updateUI:carouselArray {
NSMutableArray *array;
array = carouselArray;
//carouselArray = [[NSMutableArray alloc] init];
CGFloat x =0;
cview = [[CaroView alloc] initWithFrame:CGRectMake(x, 0, 320, 170)];
}
我在访问
carouselArray
中的updateUI:
的每一行上都收到一条警告,告诉我“ carouselArray的本地声明隐藏了实例变量”。我在NSMutableArray
中初始化了viewDidLoad
,但看不到为什么会出现问题。 最佳答案
看起来您有一个名为carouselArray
的实例变量,并且在updateUI
中有一个名为同一个东西的参数。
更改此:
-(void)updateUI:carouselArray {
NSMutableArray *array;
array = carouselArray;
//carouselArray = [[NSMutableArray alloc] init];
CGFloat x =0;
cview = [[CaroView alloc] initWithFrame:CGRectMake(x, 0, 320, 170)];
}
对此:
-(void)updateUI:myArray {
NSMutableArray *array;
array = myArray;
//myArray = [[NSMutableArray alloc] init];
CGFloat x =0;
cview = [[CaroView alloc] initWithFrame:CGRectMake(x, 0, 320, 170)];
}