Ios 自定义委托回调

Ios 自定义委托回调,ios,iphone,objective-c,delegates,Ios,Iphone,Objective C,Delegates,我刚接触iOS编程,现在面临一个问题 我在自定义委托方面遇到问题。 我试图做一个简单的自定义,它将数据返回到上一个视图控制器并弹出当前视图控制器 我有两个导航视图控制器 @protocol AddingDelegate <NSObject> @required -(void)setInformation:(Adding *)controller withObject:(Conference *)info; -(IBAction)addingConference { NSL

我刚接触iOS编程,现在面临一个问题 我在自定义委托方面遇到问题。 我试图做一个简单的自定义,它将数据返回到上一个视图控制器并弹出当前视图控制器

我有两个导航视图控制器

@protocol AddingDelegate <NSObject>

@required
-(void)setInformation:(Adding *)controller withObject:(Conference *)info;
-(IBAction)addingConference
{
    NSLog(@"Adding Button Pressed");
    conferenceObject = [[Conference alloc]init];
    conferenceObject.name = [NameTX text];
    conferenceObject.city = [CityTX text];
    conferenceObject.description = [Dectription text];
    NSMutableArray *info = [[NSMutableArray alloc] init];
    [info addObject:conferenceObject];
    [self.delegate setInformation:self withObject:conferenceObject];
    NSLog(@"adding Conference method is done");
}
@interface MainViewController : UITableViewController <AddingDelegate>

@end
1-主视图控制器 2-加入

这是在添加视图控制器中编写的协议

@protocol AddingDelegate <NSObject>

@required
-(void)setInformation:(Adding *)controller withObject:(Conference *)info;
-(IBAction)addingConference
{
    NSLog(@"Adding Button Pressed");
    conferenceObject = [[Conference alloc]init];
    conferenceObject.name = [NameTX text];
    conferenceObject.city = [CityTX text];
    conferenceObject.description = [Dectription text];
    NSMutableArray *info = [[NSMutableArray alloc] init];
    [info addObject:conferenceObject];
    [self.delegate setInformation:self withObject:conferenceObject];
    NSLog(@"adding Conference method is done");
}
@interface MainViewController : UITableViewController <AddingDelegate>

@end
我在主视图控制器的界面上编写了委托

@protocol AddingDelegate <NSObject>

@required
-(void)setInformation:(Adding *)controller withObject:(Conference *)info;
-(IBAction)addingConference
{
    NSLog(@"Adding Button Pressed");
    conferenceObject = [[Conference alloc]init];
    conferenceObject.name = [NameTX text];
    conferenceObject.city = [CityTX text];
    conferenceObject.description = [Dectription text];
    NSMutableArray *info = [[NSMutableArray alloc] init];
    [info addObject:conferenceObject];
    [self.delegate setInformation:self withObject:conferenceObject];
    NSLog(@"adding Conference method is done");
}
@interface MainViewController : UITableViewController <AddingDelegate>

@end
这是“为赛格做准备”的方法

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"AddObject"]) {
        UINavigationController *navigation = segue.destinationViewController;
        Adding *addingViewController = [[navigation viewControllers]objectAtIndex:0];
        addingViewController.delegate = self;
    }
}
现在的问题是,当我将添加推到堆栈顶部,然后填充信息并按done时,添加视图控制器不会弹出以显示主视图控制器

我尝试记录所有内容,但主视图控制器中的日志没有显示


请帮助我

我注意到在
prepareForSegue:sender:
的实现中,segue的
destinationViewController
是一个导航控制器。这让我觉得您的segue没有在当前导航堆栈上推送
AddingController
,而是展示了一个新的导航堆栈。这意味着包含
AddingController
的新导航控制器将以模式显示,因此,当您尝试弹出导航堆栈时,似乎不会发生任何事情,因为您在错误的导航堆栈上操作。如果是这样,你有两个选择:1。更改
[self.navigationController popToRootViewControllerAnimated:YES][自解除视图控制器激活:是完成:无]的代码>或2。将segue更改为推式segue而不是模式segue,并将segue直接指向Adding.m中的
AddingController

  @class Adding;

@protocol AddingDelegate
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller;
@end

@interface Adding : UIViewController

 @property (weak, nonatomic) id <AddingDelegate> delegate; // have you forgot this one


 @end
如果您想回到上一个屏幕并确保添加了导航控制器,则需要关闭

我执行了您提到的两个选项,segue是push segue,没有任何更改。现在显示一个错误,我发送了一个无效的选择器,或者您是否从第一个选项开始实际推送一个新的导航控制器?如果是,为什么?这可能会弄乱self.navigationController属性值。如果删除第二个导航控制器没有帮助,请在调用AddingController委托的方法中放置断点。运行应用程序,当遇到断点时,尝试确定是否正确设置了代理,是否接收到消息,导航控制器的状态如何,等等,直到找出问题所在。