-1

可能重复:
xcode iOS 比较字符串

试图让 UIImageview 根据用户的位置(城市)显示不同的图像,这是我得到的代码:

    [geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) {
    NSLog(@"Found placemarks: %@, error: %@", placemarks, error);
    if (error == nil && [placemarks count] > 0) {
        placemark = [placemarks lastObject];
        //Display country and city
        country.text = [NSString stringWithFormat:placemark.country];
        city.text = [NSString stringWithFormat:placemark.locality];
        if (placemark.locality==@"Cupertino")
            banner.image = [UIImage imageNamed:@"cupertino.png"];
    } else {
        NSLog(@"%@", error.debugDescription);
    }
} ];

我可以让标签显示国家和城市,但不能让 UIImageview 根据城市改变,有什么想法吗?

4

2 回答 2

1

使用isEqualToString:方法来比较字符串,比如

if ([placemark.locality isEqualToString:@"Cupertino"])
        banner.image = [UIImage imageNamed:@"cupertino.png"];
} else {
    NSLog(@"%@", error.debugDescription);
}
于 2013-01-30T03:42:53.293 回答
0

确保您已使用 [UIImage alloc] 分配图像。

于 2013-01-30T05:20:51.083 回答