我正在开发一个从Dribbble
下载图片的简单应用,但是我在为我的集合视图重新加载数据时遇到了问题。我有两个用ViewDeck
设置的视图,center是我的主视图,它包含集合视图,另一个视图包含带有设置的表视图,从那里我试图在第一个视图中调用一个方法并重新加载数据项目被点击但它不起作用。
我尝试使用按钮从主窗口调用相同的方法 - >工作就像一个魅力,但从第二个窗口,它只是不更新数据。
我尝试以某种方式进行调试,看起来我的集合在调用重载时为空,不明白为什么。
SettingsViewController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"tap");
JKViewController *appDelegate = [[JKViewController alloc] init];
appDelegate.dataHasChanged = YES;
[appDelegate refresh];
[self.viewDeckController closeLeftViewAnimated:YES];
}
的MainView
- (void)refresh{
NSLog(@"refresh");
if(dataHasChanged)
{
switch (listType) {
case 0:
[self refreshWithList:SPListPopular];
break;
case 1:
[self refreshWithList:SPListEveryone];
break;
case 2:
[self refreshWithList:SPListDebuts];
break;
case 3:
[self refreshWithList:SPListPopular];
break;
default:
[self refreshWithList:nil];
break;
}
dataHasChanged = NO;
NSLog(@"Should refresh");
}
NSLog(@"%d", [self->shots count]);
NSLog(@"Collection view: %@",self.collectionView.description);
NSLog(@"self.list: %@",self.list);
NSLog(@"List type: %d", listType);
}
这不起作用:/,但是当我从MainView中的按钮调用它时,它可以工作。
- (IBAction)changeList:(id)sender {
[self refreshWithList:SPListDebuts];
}
有谁知道这可能是什么问题?
获取centerViewController的正确实例
JKViewController *mainController = ((UINavigationController*)self.viewDeckController.centerController).visibleViewController.navigationController.viewControllers[0];
答案 0 :(得分:0)
您没有看到数据被更新的原因是因为您正在创建一个新的视图控制器并告诉它要刷新。此新视图控制器已初始化但未添加到视图层次结构中。您要做的是向现有视图控制器发送消息,如下所示:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"tap");
JKViewController *mainViewController = self.viewDeckController.centerViewController;
mainViewController.dataHasChanged = YES;
[mainViewController refresh];
[self.viewDeckController closeLeftViewAnimated:YES];
}
另外,请注意我在修订版中更改了变量名称。命名UIViewController实例'appDelegate'非常混乱。