打开接收推送通知的特定视图
我将 UITableView
作为我的 rootViewController
,并使用解析后的 RSS 填充该表(有一个 Parser
类,其中我的 rootViewController
是它的代表)。在 rootViewController
中,我有刷新 RSS refreshData
的方法,并将检索到的数据保存在静态 MutableArray
staticItems 中:
单击 中的单元格时>tableView
单元格 detailView
被推送到 navigationController
上,同时(在选择单元格(行)时)我创建并传递一个字典 theItem
到 detailView
。在该字典中,我传递来自 staticItems
和 positionInArray
(所选单元格的索引)的值。这样我就可以显示新闻文本并跟踪新闻在新闻数组中的位置以实现幻灯片上一页/下一页。
现在,我启用了推送通知,并且在收到通知后,我的应用程序返回到前台,但具有上次关闭应用程序时打开的视图。
我想通过重新解析(刷新)RSS 并呈现最新新闻 (theItem[0]),在 detailView 中呈现最新新闻。
因此,我希望得到以下结果:调用 [rootController refreshData]
,然后选择单元格中的第一项并在 detailView
中打开
它一直在使用委托方法didReceiveRemoteNotification
,但我找不到使其工作的方法。我尝试创建新的 rootController
,但随后我将其堆叠在现有的控制器上:(。
请与我分享您的想法:)
I have UITableView
as my rootViewController
and I populate that table with parsed RSS (there's a Parser
class where my rootViewController
is its delegate). In the rootViewController
I have methods for refreshing RSS refreshData
and I keep my retreived data in a static MutableArray
staticItems:
On clicking a cell in tableView
cell the detailView
gets pushed on the navigationController
while at the same time (on selecting the cell (row)) I create and pass a dictionary theItem
to the detailView
. In that dictionary I pass the values from staticItems
and the positionInArray
(index of selected cell). This way I can show the text of the news and keep track about the position of the news in the array of news to implement slide prev/next.
Now, I enabled push notifications and on receiving one my app is back to foreground but with the view that was opened last time when app was closed.
I would like to present the last news in detailView by re-parsing (refreshing) the RSS and presenting the last news (theItem[0]).
So, I would like to have the result of the following: calling the [rootController refreshData]
and then selecting the first item in the cell and opening it in detailView
I've been playing with the delegate method didReceiveRemoteNotification
, but I can't find the way of making it work. I tried creating new rootController
, but then I stack it over existing one :(.
Please share your thoughts with me :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,这个问题与推送通知根本无关。这更多的是如何从应用程序委托中的任意位置访问视图控制器的问题。
您最好的(也可能是唯一的)选择是手动保留对相关视图控制器实例的引用。
我假设您使用 UINavigationController ,其中根是您的列表,然后将详细视图控制器推送到它上面。在您的应用程序委托中保留对此导航控制器的引用。将
@property(非原子,保留)UINavigationController *mainNavController;
添加到您的应用程序委托。创建导航控制器时,对其进行分配,以便应用程序委托具有引用。如果您在应用程序委托本身中创建导航控制器,那么显然您只需要执行以下操作:
然后当您收到推送通知时,只需直接对导航控制器进行操作即可。
然后导航控制器将通过滑动动画到
MyDetailViewController
,后退按钮将带您进入列表。First of all, this question is not really related to push notifications at all. It's more a question of how to access your view controllers from an arbitrary place in your application delegate.
Your best (and possibly only) bet is to manually keep references to the relevant view controller instances.
I'm assuming you use a
UINavigationController
where the root is your list, and then you push a detail view controller onto it. Keep a reference to this navigation controller in your app delegate. Add a@property (nonatomic, retain) UINavigationController *mainNavController;
to your application delegate. When you create the navigation controller, assign it so the app delegate has a reference.If you create the navigation controller in the app delegate itself, you obviously only need to do this:
Then when you receive a push notification, simply act on the navigation controller directly.
Then the navigation controller will animate to
MyDetailViewController
with a swipe and the back button will take you to the list.