Assigning NSString to UILabel error
I am using CLLocationManager to try and grab my users latitude and longitude, cast them into an NSString and display them on screen in a UILabel using the following code;
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
CLLocationCoordinate2D location=newLocation.coordinate;
NSString *latLong = [NSString stringWithFor开发者_StackOverflow社区mat:@"%f,%f",location.latitude,location.longitude];
locationView.text = latLong;
}
Everything compiles and runs without issue, but the UILabel 'locationView' does not get populated. I have tested with just creating an NSString and trying that which works fine.
Any ideas where my error is?
Some things to try:
- Make sure locationView isn't nil.
- Make sure locationView is in the view hierarchy.
- Make sure if locationView is an IBOutlet, that you've attached the correct object in your xib.
- Make sure your delegate method is getting called.
- Make sure locationView's frame isn't CGRectZero.
Your locationView
is likely nil
at the time of the call. You may need to store the location in an instance variable and on viewDidLoad
set the locationView
text there as well.
Try to check latLong with
NSLog(@"%@", latLong);
How does locationView look like?
Try NSLog(@"%@",locationView);
to check if locationView is nil.
Is it kosher to create a new variable with the same name as a parameter? Have you tried naming your coordinate variable something else?
精彩评论