委託報關無法從呈現視圖控制器
// 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方法稱爲訪問委託方法:
// 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構建的應用程序,並將其擴展到所有設備上。這裏的實現工作(它被設置爲分割視圖控制器)。任何幫助將不勝感激
它在我看來你是設置'UINavigationController'的委託,而不是你的委託。您需要在「FolderListViewController」實例上設置委託。您也可以將您的委託屬性重命名爲'folderSelectionDelegate',以避免混淆。 – albertamg
非常感謝 - 這表明我朝着正確的方向 – user1987502