可能大家对跳转到任意控制器的理解有点不同。我自己的做法是通过通知来进行跳转的。appdelegate代理中接收到消息,将userInfo消息通过通知传出去,再此期间,需将跳转的控制器获取出来,接着其实就是获取你点击的某个控件比如cell的id传到那个控制器。然后在该控制器接收通知
就我自己的项目来说:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
if (application.applicationState == UIApplicationStateActive) {
NSLog(@"active");
//程序当前正处于前台
[application setApplicationIconBadgeNumber:0];
NSString *messageAlert = [[userInfo objectForKey:@"aps"]objectForKey:@"alert"];
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"远程通知" message:messageAlert delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"前往", nil];
alertView.delegate = self;
[alertView show];
// 8秒后将退出弹框
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(8.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[alertView dismissWithClickedButtonIndex:0 animated:YES];
});
}
else if(application.applicationState == UIApplicationStateInactive)
{
NSLog(@"inactive");
//程序处于后台
// 发送通知到需要跳转的控制器中
[[NSNotificationCenter defaultCenter]postNotificationName:@"123456" object:nil userInfo:userInfo];
}
// IOS 7 Support Required
[APService handleRemoteNotification:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
}
在你首页控制器的注册通知,并且跳转到每个要进入的页面
- (void)viewdidload
{
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(pushNotification:) name:@"123456" object:nil];
}
- (void)pushNotification:(NSNotification *)notification
{
NSDictionary *dict = notification.userInfo;
// kpiid 其实就是后台传出来需要点击cell的id
GTLog(@"===notification===%@",[dict valueForKey:@"kpiid"]);
[self selectKPIModuleId:[[dict valueForKey:@"kpiid"] integerValue]];
}
/************************************************
*
*
* 点击相对应的kpiid模块,跳转到相对应的kpi控制器
*
*
************************************************/
- (void)selectKPIModuleId:(int)kpiid // 此处是tableview didselect方法中单独提取的方法
{
//销售利润
if(kpiid==1){
ProfitViewController *pyc=[[ProfitViewController alloc] initWithNibName:@"ProfitViewController" bundle:nil];
[(UINavigationController *)self.mm_drawerController.centerViewController pushViewController:pyc animated:YES];
[[TimeTool sharedTimeTool] timeToolBTypeOfStartWhenIntoViewCurrentModuleID:1];
return;
}
大致的跳转就是这样的 所以说开发中没有变态不变态的需求 ,既然别人能想出来,必然可以去实现。so,有些事需要自己多想。后面有实现流程图,可以看一下