嗨,我正在开发一款应用程序,直到现在一直都很好......我在这一点上陷入困境...... 这是我的故事板快照..
按钮..品牌TableViewController以模态方式打开。 用户在Brands TableViewController中选择多行后,然后点击完成按钮,视图控制器被此代码解除:
-(IBAction)DonePressed:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
我将用户选择存储在NSMutableSet中,它将在DemoTableViewController中使用,以便我可以根据选择重新加载表行,但我不知道如何将NSMutableSet发送到DemoTableViewController,然后根据选择重新加载表。 。 什么是解除模态视图并重新加载父DemoTableViewController的正确方法 我知道我做得不对,但任何人都可以帮我做这件事...... 这里有一些代码--- DemoTVC.h
#import <UIKit/UIKit.h>
#import "MyModelClass.h"
#import "brandsTableViewController.h"
@interface demoTableViewController : UITableViewController<UITableViewDataSource,UITableViewDelegate,MyModelProtocol,FilterProtocol>
@property (strong, nonatomic) IBOutlet UITableView *demoTable;
- (IBAction)FilterPressed:(id)sender;
@end
DemoTVC.m-- 执行segue的方法 -
- (IBAction)FilterPressed:(id)sender {
[self performSegueWithIdentifier:@"FilterPressed" sender:self];
}
调用委托方法从BrandsTVC获取值 -
-(void)GetTheSet:(NSMutableSet *)MySet{
[self dismissViewControllerAnimated:YES completion:nil];
}
viewDidLoad中 -
- (void)viewDidLoad
{
[super viewDidLoad];
productArray = [[NSMutableArray alloc] init];
homeModel = [[MyModelClass alloc] init];
// Set this view controller object as the delegate for the home model object
homeModel.delegate = self;
// Call the download items method of the home model object
[homeModel downloadItemswithurl:@"url is written here"];
}
BrandsTVC.h ---
#import <UIKit/UIKit.h>
#import "MyModelClass.h"
@protocol FilterProtocol <NSObject>
-(void)GetTheSet:(NSMutableSet *) MySet;
@end
@interface brandsTableViewController : UITableViewController<UITableViewDataSource,UITableViewDelegate,MyModelProtocol>
@property (strong, nonatomic) IBOutlet UITableView *RetailerList;
@property (strong,nonatomic) NSMutableSet *selectStates;
@property (nonatomic, weak) id<FilterProtocol> delegate;
- (IBAction) DonePressed:(id)sender;
@end
BrandsTVC.m ---
@interface brandsTableViewController ()
{
MyModelClass *myModelClass;
NSMutableArray *BrandsArray;
brandsTableViewController *Delegate;
}
@end
viewDidLoad中----
- (void)viewDidLoad
{
[super viewDidLoad];
BrandsArray = [[NSMutableArray alloc] init];
self.selectStates=[NSMutableSet new];
myModelClass = [[MyModelClass alloc] init];
// Set this view controller object as the delegate for the home model object
myModelClass.delegate = self;
// Call the download items method of the home model object
[myModelClass downloadItemswithurl:@"url to get json"];
self.tableView.allowsMultipleSelection = YES;
}
完成按钮被称为---
- (IBAction)DonePressed:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
id<FilterProtocol> strongDelegate = self.delegate;
if ([strongDelegate respondsToSelector:@selector(GetTheSet:)]) {
[strongDelegate GetTheSet:self.selectStates];
}
}
@end
答案 0 :(得分:0)
您可以将这些元素保留在NSUserDefaults中,每当DemoTableViewController出现时,您都会发送[tableView reloadData]。在viewDidAppear:方法中执行此操作。
您也可以使用核心数据,但有很多细节可以解释如何做到这一点。
答案 1 :(得分:0)
经过大量的反复试验后,我在BrandsTVC中了解到了这一点 -
- (IBAction)DonePressed:(id)sender {
NSLog(@"done pressed %@",self.delegate);
[delegate GetTheSet:self.selectStates];
}
self.delegate给我NULL。 代表没有设置,我无法弄清楚如何做到这一点..有人帮助我..
这个答案解决了我的问题:D custom viewcontroller delegate not working