【问题标题】:Reload UIWebView when a new push notification arrives当新的推送通知到达时重新加载 UIWebView
【发布时间】:2012-04-09 17:23:30
【问题描述】:

我对 Objective-C 编程还很陌生,但我很努力:-)。我正在开发一个具有 2 个 UIWebViews 的小应用程序(通过 2 个工具栏按钮访问)。

我已经实现了推送通知服务,一切正常...

我现在想做的是在收到新的推送通知时重新加载 UIWebView。 我猜它应该在我的 AppDelegate.m 中:

- (void) application:(UIApplication *) application didReceiveRemoteNotification:(NSDictionary *) userInfo {

我想做类似的事情:

[FirstUIWebView reload];

但我不知道如何从 appdelegate 控制视图..

您的帮助将不胜感激..

罗曼

【问题讨论】:

    标签: iphone objective-c xcode


    【解决方案1】:

    您可以在 appDelegate 类中拥有一个 UIViewController* 属性,该属性引用包含 UIWebView* 视图对象的控制器。控制器将公开引用视图的IBOutlet UIWebView* 属性。

    然后你可以从 appDelegate 方法中调用 reload UIWebView 如:

    [webViewController.webView reload]
    

    【讨论】:

    • 感谢您的快速回复,所以我做了@property (nonatomic, readonly) UIViewController *webViewController;在 AppDelegate.h 中,如何让这个 webViewController 引用我的控制器(FirstViewController),其中包含我试图重新加载的 UIWebView(reservationWebView)?再次感谢,抱歉这个可能很愚蠢的问题.. 罗曼
    • 初始化控制器的方法是:self.webViewController = [[[FirstViewController alloc] initWithNibName:@"WebViewController" bundle:nil] autorelease];
    • “WebViewController”是 .xib 文件名。
    • 好的,所以我会在“应用程序 didFinishLaunchingWithOptions:”中执行此操作:self.webViewController = [[FirstViewController alloc] initWithNibName:@"webViewController" bundle:nil];唯一的问题是我使用故事板。我确实在我的视图上将标识符设置为 FirstIdentifier 并尝试使用此处提供的解决方案来解决它:tinyurl.com/6nld23c 不幸的是它仍然无法正常工作......
    • 我这样声明了一个故事板:@property(nonatomic, readonly, retain) UIStoryboard *storyboard;然后在 m 文件中:storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; self.webViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"FirstIdentifier"];然后我尝试使用 [webViewController.webView reload];但我无法在 webViewController 中访问 webView.. 我觉得我越来越近了.!?再次Tkx
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-31
    • 1970-01-01
    • 1970-01-01
    • 2013-11-23
    • 1970-01-01
    相关资源
    最近更新 更多