0
我試圖實現一個car2go風格的應用程序,你點擊一個註釋視圖,然後可以預訂汽車。問題是,當我嘗試繼續我想要傳遞車對象時,我檢查對象是否執行選擇器設置車輛,但if語句失敗,儘管我很確定它已實現。有人能告訴我爲什麼嗎?這是一個學校項目。類的安裝程序不被稱爲
#import "MapViewController.h"
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
#import "Vehicles+Company.h"
#import "Vehicles+MKAnnotation.h"
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:@"reserveCar"]) {
if ([sender isKindOfClass:[MKAnnotationView class]]) {
MKAnnotationView *aView = sender;
if ([aView.annotation isKindOfClass:[Vehicles class]]) {
Vehicles *vehicle = aView.annotation;
if ([segue.destinationViewController respondsToSelector:@selector(setVehicle:)]) {
[segue.destinationViewController performSelector:@selector(setVehicle:) withObject:vehicle];
}
}
}
}
}
這是它延續到的視圖控制器。
.h文件中
#import <UIKit/UIKit.h>
#import "Vehicles+MKAnnotation.h"
#import "Vehicles.h"
#import "Vehicles+Company.h"
@interface CompanyVehicleViewController : UIViewController
@property (nonatomic,strong) Vehicles *vehicle;
@end
.m文件
#import "CompanyVehicleViewController.h"
@interface CompanyVehicleViewController()
@end
@implementation CompanyVehicleViewController
-(void) setVehicle:(Vehicles *)vehicle{
_vehicle = vehicle;
self.title = vehicle.name;
NSLog(@"Vehicle is %@", vehicle);
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
@end
確認'segue.destinationViewController'確實是'CompanyVehicleViewController'的一個實例。 – rmaddy
我該怎麼做? – user2076774
使用調試器或添加一個'NSLog'語句。 – rmaddy