首先确保你alloc
,init
您tableViewArray
在HomeViewController
二,在这一行
HomeViewController *homeVC = [[HomeViewController alloc] init]
您要创建一个新的引用您的HomeViewController
这是不正确的,你需要传递正确的引用,可能在你的OutsideViewController
创建HomeViewController变量即使你做正确的第一和第二个建议,你仍然会看到一个空tableview因为你不重新加载tableview,不知何故你需要发射[self.tableview reloadData];
方法。
这意味着;你需要学习代表或NSNotifications模式父场景
How do I set up a simple delegate to communicate between two view controllers?
http://mobile.tutsplus.com/tutorials/iphone/ios-sdk_nsnotificationcenter/
对于你的问题只是在你的Outside
创建委托之间的儿童安全通信>; 在OutsideViewController.h
#import <UIKit/UIKit.h>
@protocol OutsideDelegate;
@interface{}//bunch of interface stuff
// Declare a property for the delegate
@property (weak) id <OutsideDelegate> delegate;
@end
// Protocol Header
@protocol OutsideDelegate <NSObject>
@optional
- (void)dismissPop:(NSMutableArray *)list;
@end
在OutsideViewController.m
@synthesize delegate;
//run delegate method
[delegate dismissPop:temporaryArray];
[self dismissViewControllerAnimated:YES completion:^{ }];
在HomeViewController
。^ h
#import "OutsideViewController.h"
@interface OutsideViewController : UITableViewController<OutsideDelegate>
{}
@property (strong, nonatomic) OutsideViewController *pvc;
在HomeViewController.m
@synthesize pvc;
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"your segue"]) {
pvc = [segue destinationViewController];
[pvc setDelegate:self];
}
}
// delegate callback function
- (void)dismissPop:(NSMutableArray *)list {
self.tableViewArray=list;
[self.tableView reloadData];
}
另一个解决方案是
视图栈改成这样:
Navigation Controller --> HomeViewController -(push segue)--> OutsideViewController
和应用rdurand的回答
,并添加到您的HomeViewController:
-(void)viewDidAppear:(BOOL)animated
{
[self.tableview reloadData];
}
在这个解决方案,因为你,当你弹出OutsideViewController处于nabigation堆栈viewDidAppear
只是把流行viewcontrollers将在HomeViewController每次调用。
我使用全局单例类,它可以存储需要从任何控制器访问的数组等东西。 –