委托声明
// FolderListViewController.h
#import <UIKit/UIKit.h>
#import "Folder.h"
@protocol FolderSelectionDelegate <NSObject>
@required
- (void)setFolder:(Folder *)folder;
@end
@interface FolderListViewController : UITableViewController
@property (nonatomic, assign) id<FolderSelectionDelegate> delegate;
- (IBAction)showDashboard:(id)sender;
@end
从didSelectRowAtIndexPath:
调用Delegate// FolderListViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self.delegate setFolder:dataSource[indexPath.row]];
}
应该接收消息的VC
#import <UIKit/UIKit.h>
#import "FolderListViewController.h"
#import "Folder.h"
@interface ProjectListViewController : UITableViewController <FolderSelectionDelegate, UISplitViewControllerDelegate, UISearchBarDelegate, UINavigationControllerDelegate>
@property (nonatomic,retain)UIActivityIndicatorView *activityIndicatorObject;
@property (nonatomic, copy)Folder *folder;
-(void)loadProjects:(Folder*)folder;
@end
呈现VC的行动
- (void)foldersButtonTapped {
UINavigationController *vc = [[UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil] instantiateViewControllerWithIdentifier:@"FolderListNavController"];
vc.delegate = self;
[self presentViewController:vc animated:YES completion:nil];
}
委托方法实施
- (void)setFolder:(Folder *)folder {
_folder = folder;
[self loadProjects:folder];
}
我在这里阅读了多个主题并且没有运气。首先,在呈现FolderListVC(即vc.delegate = self)时,我没有引用ProjectListVC设置。尽管如此,这似乎不是问题所在。我正在开发一款专为iPad打造的应用程序,并将其扩展为适用于所有设备。这里的实现是有效的(它被设置为分割视图控制器)。任何帮助将不胜感激
答案 0 :(得分:0)
我认为UINavigationcontroller正在创建问题,因为它没有设置FolderListViewController委托。你能尝试这样吗。
FolderListViewController *vc=[self.storyboard instantiateViewControllerWithIdentifier:@"FolderListViewController"];
vc.delegate=self; // protocol listener
[self.navigationController pushViewController:vc animated:YES];