开发者

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:

  1. Make sure locationView isn't nil.
  2. Make sure locationView is in the view hierarchy.
  3. Make sure if locationView is an IBOutlet, that you've attached the correct object in your xib.
  4. Make sure your delegate method is getting called.
  5. 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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜