0

我使用委托和协议创建了一个简单的 TableView 应用程序,它在 ios 5 中工作,但是当我更新我的 xcode 时,我在 ios 6 中无法工作。代码是这样的:

在子视图中:

@class AddItemViewController;
@class CheckListItem;
@protocol AddItemViewControllerDelegate <NSObject>

- (void)addItemViewControllerDidCancel: (AddItemViewController *)controller;
- (void)addItemViewController:(AddItemViewController *)controller didFnishAddingItem:(CheckListItem *)item;

@end


@interface AddItemViewController : UITableViewController <UITextFieldDelegate>

//declare an property
@property (nonatomic, assign) id <AddItemViewControllerDelegate> delegate;

in childview.m:
- (void)addItemViewControllerDidCancel: (AddItemViewController *)controller{
//i do something here
}

in parentview.h:
#import "AddItemViewController.h"

@interface CheckListViewController : UITableViewController <AddItemViewControllerDelegate>

-(IBAction)addItem;

@end

in parentview.m:
- (void)addItemViewControllerDidCancel:(AddItemViewController *)controller
{
    [controller dismissViewControllerAnimated:YES completion:nil];

}
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if([segue.identifier isEqualToString:@"AddItem"]){
        UINavigationController *navigationController = segue.destinationViewController;
        AddItemViewController *controller = (AddItemViewController *)navigationController;
        controller.delegate = self;
        NSLog(@"perform prepare for segue");

    }
}

这段代码有什么问题吗?谢谢

4

1 回答 1

0

在您的子视图中,您必须调用 [delegate addItemViewControllerDidCancel: (AddItemViewController *)controller],而不仅仅是调用该方法。

如果你改变它,它应该可以工作:)

于 2013-01-02T08:26:28.363 回答