这是我的代码,显示地图上当前位置的警报和蓝点:
MapName.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
@interface MapName : UIViewController <MKMapViewDelegate, CLLocationManagerDelegate>
@property (strong, nonatomic) IBOutlet MKMapView *MapName;
@property (strong, nonatomic) CLLocationManager *locationManager;
@end
Run Code Online (Sandbox Code Playgroud)
MapName.m
- (void)viewDidLoad
{
[super viewDidLoad];
self.locationManager = [[CLLocationManager alloc]init];
self.locationManager.delegate = self;
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[self.locationManager requestWhenInUseAuthorization];
}
[self.locationManager startUpdatingLocation];
//Center the map
[self gotoLocation];
//Show current position
_MapName.showsUserLocation = YES;
}
Run Code Online (Sandbox Code Playgroud)
我已将密钥NSLocationWhenIsUseUsageDescription作为字符串添加到Info.plist中.我在Xcode上仍然遇到同样的错误.
我在这里看到了一些关于相同错误的问答,但没有一个有帮助。我仍然遇到同样的错误。我需要改变什么?这就是我现在所拥有的。
错误与这一行有关: imageIndex = (imageIndex < 0) ? ([图像数] -1):
感谢您的帮助!
#import "Photogallery.h"
@interface Photogallery ()
@end
@implementation Photogallery
@synthesize imageView;
int imageIndex = 10;
- (void)viewDidLoad {
[super viewDidLoad];
}
- (IBAction)handleSwipe:(UIGestureRecognizer *)sender {
NSArray *images=[[NSArray alloc]initWithObjects:@"1.jpg",@"2.jpg",@"3.jpg",@"4.jpg",@"5.jpg",@"6.jpg",@"7.jpg",@"8.jpg",@"9.jpg",@"10.jpg", nil];
UISwipeGestureRecognizerDirection direction = [(UISwipeGestureRecognizer *)sender direction];
switch (direction) {
case UISwipeGestureRecognizerDirectionLeft:
imageIndex++;
break;
case UISwipeGestureRecognizerDirectionRight:
imageIndex--;
break;
default:
break;
}
imageIndex = (imageIndex < 0) ? ([images count] -1):
imageIndex % [images count];
imageView.image = [UIImage imageNamed:[images objectAtIndex:imageIndex]];
}
@end
Run Code Online (Sandbox Code Playgroud)