NSMutableArray警告的本地声明

时间:2014-05-16 20:59:54

标签: ios objective-c

我在此方法中向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,但我看不出为什么会遇到这个问题。

3 个答案:

答案 0 :(得分:1)

看起来你有一个名为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)];

}

答案 1 :(得分:0)

  

我收到警告说“carouselArray的本地声明隐藏了   实例变量“

在这个方法中的某个地方你正在做的事情:

NSMutableArray *carouselArray = ...

你有一个名为carouselArray的实例变量的事实使编译器吐出警告。


答案 2 :(得分:0)

尝试

-(void)updateUI:(NSMutableArray*)myCarouselArray {

...

array = myCarouselArray;

然后从那里开始。