我有一个使用默认模板主详细信息制作的应用程序。我想将一个字符串从详细视图传递到主视图,点击一个按钮。我使用了这段代码:
细节视图控制器.h
@protocol DetailViewControllerDelegate <NSObject>
- (void)passItemToMaster:(id)controller didFinishEnteringItem:(NSString *)item;
@end
@interface DetailViewController : UIViewController<UITextFieldDelegate>
{
NSString *itemToPassBack;
}
@property (copy) NSString *itemToPassBack;
@property (retain) id delegate;
@end
细节视图控制器.m
-(IBAction)passBack:(id)sender
{
itemToPassBack = [[NSString alloc] initWithFormat:@"PassedBack"];
[[self delegate] addItemViewController:self didFinishEnteringItem: itemToPassBack];
[self.navigationController popViewControllerAnimated:YES];
}
主视图控制器.h
@interface MasterViewController : UITableViewController <DetailViewControllerDelegate>
@property (nonatomic) NSString *returnedItem;
@end
主视图控制器.m
-(void) passItemToMaster:(id) controller didFinishEnteringItem: (NSString *)item
{
returnedItem = item;
NSLog(@"This was returned from secondPageViewController");
}
如何在主视图中获取对象?nslog 不显示任何内容。