您不能像这样简单地将其传递到 prepareForSegue 方法中的任何原因:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
switch segue.identifier {
case "tableViewController"?:
if let tableViewVC = segue.destinationViewController as? TableViewVC {
tableViewVC.myArray = passedArray
} ...
哦 - obj-c 在伪代码中会是这样的:
- (void)prepareForSegue:(NSStoryboardSegue*)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"tableViewController"]) {
NSViewController *vc = [segue destinationController];
if ([vc isKindOfClass:[tableViewVC class]]) {
tableViewVC.myArray = passedArray;
没有看到你的标签:]
编辑:
以下是通过通知传递的大致内容:
在你的 UIViewController 的标题中声明:
#define nArrayReadyNotification @"ArrayReadyNotification"
在您的 UIViewController 的 .m 文件中,在发送数组后发送通知:
[[NSNotificationCenter defaultCenter] postNotificationName: nArrayReadyNotification object:ARRAY];
在您的 tableView 的 viewDidLoad 注册通知中:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(arrayReceived:) name: nArrayReadyNotification object:nil];
这将是您的表格视图中的 arrayReceived 方法:
- (void) arrayReceived:(NSNotification *)notificaiton {
NSArray *array = [notificaiton object];
if (array != nil) {
...
}
最后在 dealloc 中取消注册您的表视图:
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
这应该可以在您想要的任何时候发送 - 也许在计时器之外。不过,KVO 会是我的首选。