我试图使用下面的代码(从我的主ViewController调用)设置自定义类的CLLocation属性(名为objectLocation)。不幸的是,我在“注释的”行上收到一个错误消息,告诉我“表达式不可分配”。 locationsArray是自定义类的对象数组。我确实需要设置此值,因此我们将为您提供帮助!

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
for (int i = 0; i < [locationsArray count]; i++) {

if ([locationsArray[i] objectLocation] == NULL) {
    [locationsArray[i] objectLocation] = [locations lastObject]; //retrieves most recent location data - THIS IS THE LINE THAT RECEIVES THE ERROR
    //now set up a region and start monitoring data for that region
    [locationsArray[i] region] = [[CLRegion alloc]
                                          initCircularRegionWithCenter:
                                          [[locationsArray[i] objectLocation] coordinate]
                                                                radius:2
                                                            identifier:[NSString stringWithFormat:@"%@", [locationsArray[i] objectLocationName]]];
       }
}
}

最佳答案

如果它是类中CLLocation的属性,并且假定您的locationsArray持有该对象,而您的locations数组确实持有一个CLLocation对象,则请尝试以下操作:

((<YOUR_CLASS>*)[locationsArray[i]).objectLocation = [locations lastObject];


希望这可以帮助。

关于ios - 无法设置属性CLLocation,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23979468/

10-14 22:32