我使用委托和协议创建了一个简单的 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");
}
}
这段代码有什么问题吗?谢谢