2013-01-02 89 views
0

我已經創建了一個簡單的TableView應用程序使用委託和協議,它在ios 5中工作,但是當我更新我的xcode時,我不工作在ios 6. 代碼就像這樣的:委託和協議在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"); 

    } 
} 

有什麼不對的代碼? 謝謝

回答

0

在你的子視圖中,你必須調用[delegate addItemViewControllerDidCancel:(AddItemViewController *)controller],而不是調用方法。

如果你改變它,它應該工作:)