【问题标题】:Calling method in MyAppDelegate.m to ViewController将 MyAppDelegate.m 中的方法调用到 ViewController
【发布时间】:2012-04-24 06:13:03
【问题描述】:

我有 GridViewController。

@interface GridViewController : UIViewController <AQGridViewDelegate, AQGridViewDataSource, LoginViewControllerDelegate, IconDownloaderDelegate, UIScrollViewDelegate> {

NSArray *objects; //main data model
NSMutableDictionary *imageDownloadsInProgress;

}

@property (nonatomic, retain) IBOutlet AQGridView *gridView;

我需要调用我的 gridview 的 reloadData 方法。

当我在 GridViewController.m (viewDidLoad) 中调用 [self.gridView reloadData]; 时,

它重新加载没有问题。

但是我需要在 AppDelegate.m 中调用这个方法

所以我在 AppDelegate.m 中导入“GridViewController.h”

#import "AppDelegate.h"
#import "GridViewController.h"

并调用方法,

[gridViewController.gridView reloadData];

它不工作。

如何从我的 delegate.m 调用此方法到 GridViewController 的 gridView?

【问题讨论】:

  • 你有没有试过调试,是否控制到数据源和表视图的委托方法?
  • 您的应用委托中是否引用了当前的 GridView 控制器。我的意思是 gridViewController 实际上是屏幕上的控制器?
  • 感觉我需要另一个关于如何调试的“问一个问题”,或者干脆退出。哈哈!谢谢。
  • 阿迪尔·苏姆罗。是的,它实际上在运行时显示在屏幕上。但我没有在情节提要中成功。

标签: iphone ios delegates reloaddata aqgridview


【解决方案1】:

尝试在您的 AppDelegate 中发布您的 GridViewController 将捕获的通知。 在 AppDelegate.m 的某个地方,您需要调用您的网格重新加载代码:

[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadGrid" object:nil];

在您的 GridViewController 的 viewDidLoad 中:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadMyGrid)name:@"reloadGrid" object:nil];

在您的 GridViewController 的 viewDidUnload 中:

[[NSNotificationCenter defaultCenter] removeObserver:self];

您需要向 GridViewController 添加方法:

- (void)reloadMyGrid {
     [self.gridView reloadData];
}

【讨论】:

  • 当您需要从 B 类调用 A 类中的某些代码时,这通常可以解决问题 :)
猜你喜欢
  • 2015-11-10
  • 1970-01-01
  • 1970-01-01
  • 2015-05-19
  • 1970-01-01
  • 2023-03-03
  • 1970-01-01
  • 2014-05-20
  • 2014-11-18
相关资源
最近更新 更多