2 yue1liang1chuan yue1liang1chuan 于 2013.08.26 11:00 提问

IOS-MapView的错误

使用MapView中, ViewController.m添加这行代码之后就会报错:

mapView.delegate = self;

错误:

Assigning to 'id<MKMapViewDelegate>' from incompatible type 'ViewController *const 
__strong'

代码:

ViewController.m:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize mapView;

- (void)viewDidLoad
{
    [super viewDidLoad];
    mapView.showsUserLocation = YES;
    mapView.delegate = self; //The line I added that creates the error
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

ViewController.h

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>

@interface ViewController : UIViewController {
    MKMapView *mapview;
}
@property (weak, nonatomic) IBOutlet MKMapView *mapView;

@end

AppDelegate.m

#import "AppDelegate.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end

AppDelegate.h

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end

2个回答

lanhailvcao
lanhailvcao   2013.08.26 13:58
已采纳

需要声明你的类 MKMapViewDelegate 方法。在ViewController.h 头文件中,修改

@interface ViewController : UIViewController {

改为:

@interface ViewController : UIViewController <MKMapViewDelegate> {
yue1liang1chuan
yue1liang1chuan 谢谢,我忘了这步了
接近 5 年之前 回复
u013243469
u013243469   2014.11.26 13:15

在.h文件中添加代理协议了吗?

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
错误错误还是错误
<br />
错误与“错误”
从小到大,我们都觉得犯了错误是一个很不光彩的事情。比如说,因为自己的调皮打 碎了邻居家的玻璃,或者点着了他们的柴火等等。当然,因此换来的当然是父母的一顿 臭骂,或者是更严重……因此,在我们的心里也有了这样一个“道理”,只有不犯错误的孩 子才会是一个好孩子,然后我们就这样遵循着这个似乎挺正确的道理长大了……     可是,我想说的是,并非所有的错误都是值得我们痛恨的。或者说,犯错
Oracle 约束错误约束错误
Oracle 约束错误约束错误Oracle 约束错误约束错误
anywhere错误
anywhere错误anywhere错误anywhere错误anywhere错误
sql错误
sql错误sql错误sql错误
错误的数据库
错误的数据库 错误的数据库 错误的数据库
错误?
这几天CSDN的BLOG老是出错啊,有时用户登录也不行。“/”应用程序中的服务器错误。 运行时错误 说明: 服务器上出现应用程序错误。此应用程序的当前自定义错误设置禁止远程查看应用程序错误的详细信息(出于安全原因)。但可以通过在本地服务器计算机上运行的浏览器查看。
错误
system.web.aspnethostingpermission, system, version=2.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089”类型的权限已失败
错误!!!
1.判断句i==x; 2.累加值初始值为0; 3.&&和;||或; 4.输出不能忘记; 5.注意是否有更优的办法,优化程序; 6.题目思维; 7.循环注意格式要清晰; 8.思路要可行; 9.题目看仔细,不能漏看一些重要条件; 10.老老实实按照讲过的格式书写(除非试验过完全可行); 11.代码要清晰,看起来要美观; 12.pow函数返回值为double类型; 13.doub
错误,
题目,杭电2016,http://acm.hdu.edu.cn/showproblem.php?pid=2016 值得注意的是,假如没有元素比第一个元素大,一定要设那个c=1;