Ios 为什么我的自定义协议没有被调用?目标-C

Ios 为什么我的自定义协议没有被调用?目标-C,ios,objective-c,Ios,Objective C,我有两个VC,一个是用户用textfield或pickerview编写数据,另一个是主屏幕,我在tableview上显示数据。问题是,当我单击“完成”按钮时,它可能会调用委托,但在实现的第一个vc上,它不会收到任何调用。我该怎么办?我已经花了两天的时间试图找到这个bug,但什么也没发生。谢谢你的帮助 2VC.h 最后是第1个VC的实现: -(void)didCreateCountry:(CountryClass *)country{ //Add new country-itemCoun

我有两个VC,一个是用户用textfield或pickerview编写数据,另一个是主屏幕,我在tableview上显示数据。问题是,当我单击“完成”按钮时,它可能会调用委托,但在实现的第一个vc上,它不会收到任何调用。我该怎么办?我已经花了两天的时间试图找到这个bug,但什么也没发生。谢谢你的帮助

2VC.h

最后是第1个VC的实现:

-(void)didCreateCountry:(CountryClass *)country{

    //Add new country-itemCountry - UPDATING OUR MODEL DATA

    NSMutableArray *mutableCountries = [self.countries mutableCopy];

    [mutableCountries addObject:country];

    self.countries = [mutableCountries copy];

    //UPDATING THE VIEW

    [self.tableView reloadData];

    NSLog(@"Created");

    [self saveCountriesToDisc];

}

-(void)saveCountriesToDisc{

    NSMutableArray* convertedCountries = [NSMutableArray array];

    //Converting the model to dictionary

    for(CountryClass *country in self.countries)
    {
        NSDictionary *convertedCountry = [shop countriesToDictionary];
        [convertedCountries addObject:convertedCountry];
    }

    //NOW convertedShows CONTAINS ONLY STRINGS, NUMBERS,
    //ARRAYS AND DICTIONARY
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *documentsDirectory = paths.firstObject;

    NSString *destinationPath = [documentsDirectory stringByAppendingPathComponent:@"countriesListData.plist"];

    //NOW TELL THE ARRAY TO SAVE
    [convertedCountries writeToFile:destinationPath atomically:YES];

    NSLog(@"Saved");

    [self.tableView reloadData];

}
我在prepareforsegue上初始化我的委托

-(void)prepareForSegue:(UIStoryboardSegue *)segue
                sender:(id)sender
{


      if ([segue.identifier isEqualToString:@"AddSegue"]) {

            AddCountryViewController* addCountryVC =
            segue.destinationViewController;
            addCountryVC.customDelegate = self;

    }

在VC1中,您在哪里将customDelegate设置为
self


此外,您还应将您的委托设置为
分配

在VC1中,您在哪里将customDelegate设置为



此外,您应该将您的代理设置为
分配

在哪里初始化代理?我猜你的代表是零。我想我初始化的顺序是:编辑了主要问题。这不是方法吗?这部分被称为“准备”吗?是的,它完全适用于第二个,也适用于第一个,但是没有调用委托实现。您在哪里初始化委托?我猜你的代表是零。我想我初始化的顺序是:编辑了主要问题。这不是方法吗?这部分被称为“准备”吗?是的,它完全适用于第二个,也适用于第一个,但是没有调用委托实现。您在哪里初始化委托?我猜你的代表是零。我想我初始化的顺序是:编辑了主要问题。这不是方法吗?这部分被称为“准备”吗?是的,它完全适用于第二个问题,也适用于第一个问题,但是没有调用委托实现。我想我是在Segue上初始化的:编辑了主要问题。这不是做这件事的方法吗?我在网上读到的关于弱者的作业几乎是一样的,我两个都试过了,但都没发生什么事。我改成弱者去试,但仍然不起作用。我需要在第1个ViewDiLoad或类似的东西上初始化代理吗?不,你所做的应该可以,第1个VC.h你有吗?@interface ViewController:UIViewController我不知道哪里出错了:(我想我是在Segue上初始化的:编辑了主要问题。这不是应该做的吗?关于我在互联网上读到的弱赋值,几乎是一样的,我两个都试过了,但都没有发生什么事。我改为弱赋值,但仍然不起作用。我需要在第一个ViewDiLoad或类似的东西上初始化代理吗?不,你做了什么uld工作,第一个VC.h你有?@interface ViewController:UIViewController我不知道哪里出错了:(我想我是在Segue上初始化的:编辑了主要问题。这不是应该做的吗?关于我在互联网上读到的弱赋值,几乎是一样的,我两个都试过了,但都没有发生什么事。我改为弱赋值,但仍然不起作用。我需要在第一个ViewDiLoad或类似的东西上初始化代理吗?不,你做了什么uld工作,第一个VC.h你有?@interface ViewController:UIViewController我不知道哪里出错了:(
-(void)didCreateCountry:(CountryClass *)country{

    //Add new country-itemCountry - UPDATING OUR MODEL DATA

    NSMutableArray *mutableCountries = [self.countries mutableCopy];

    [mutableCountries addObject:country];

    self.countries = [mutableCountries copy];

    //UPDATING THE VIEW

    [self.tableView reloadData];

    NSLog(@"Created");

    [self saveCountriesToDisc];

}

-(void)saveCountriesToDisc{

    NSMutableArray* convertedCountries = [NSMutableArray array];

    //Converting the model to dictionary

    for(CountryClass *country in self.countries)
    {
        NSDictionary *convertedCountry = [shop countriesToDictionary];
        [convertedCountries addObject:convertedCountry];
    }

    //NOW convertedShows CONTAINS ONLY STRINGS, NUMBERS,
    //ARRAYS AND DICTIONARY
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *documentsDirectory = paths.firstObject;

    NSString *destinationPath = [documentsDirectory stringByAppendingPathComponent:@"countriesListData.plist"];

    //NOW TELL THE ARRAY TO SAVE
    [convertedCountries writeToFile:destinationPath atomically:YES];

    NSLog(@"Saved");

    [self.tableView reloadData];

}
-(void)prepareForSegue:(UIStoryboardSegue *)segue
                sender:(id)sender
{


      if ([segue.identifier isEqualToString:@"AddSegue"]) {

            AddCountryViewController* addCountryVC =
            segue.destinationViewController;
            addCountryVC.customDelegate = self;

    }