FlipsideViewController没有解雇

时间:2013-01-21 17:34:31

标签: ios objective-c views

我的FlipsideViewController的“完成”按钮不起作用(没有崩溃,但也没有解雇视图)。这是代码:

在FlipSideViewController.h中

@class FlipsideViewController;

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

@interface FlipsideViewController : UIViewController

@property (weak, nonatomic) id <FlipsideViewControllerDelegate> delegate;

- (IBAction)done:(id)sender;

@end

在FlipSideViewController.m

- (IBAction)done:(id)sender
{
// an NSLog statement that is here is logging properly
[self.delegate flipsideViewControllerDidFinish:self];

}

在MainViewController.h中

@interface FifthViewController : UIViewController <FlipsideViewControllerDelegate> 
...

在MainViewController.m中

- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller
{
[self dismissViewControllerAnimated:YES completion:nil];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showAlternate"]) {
    [[segue destinationViewController] setDelegate:self];
}
}

顺便说一句,这是一个标签式应用程序,所以我认为这可能与它有关。任何建议,将不胜感激。谢谢。

2 个答案:

答案 0 :(得分:0)

试试这个:

- (IBAction)done:(id)sender
{
   // an NSLog statement that is here is logging properly
   [self.delegate performSelector:@selector(flipsideViewControllerDidFinish:)
            withObject:self
            afterDelay:0.0];
}

有时候必须在运行循环的下一次迭代中执行解除。这就是上面的performSelector语句完成的内容。

答案 1 :(得分:0)

我发现了问题。如果你查看问题代码,在MainViewController.m下,你必须在storyboard文件和代码中设置segue标识符:

if ([[segue identifier] isEqualToString:@"showAlternate"]) {
[[segue destinationViewController] setDelegate:self];
}

谢谢你,塞尔吉奥,谢谢你。