类的二传手没有被调用

类的二传手没有被调用

我正在尝试实现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的实例。

在情节提要中验证是否将视图控制器的类型设置为正确的类。

关于ios - 类的二传手没有被调用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22652206/

10-09 02:39