返回首页

需求场景,例如在购物车模块,我们一直往下走会走到支付成功页面,这时可能就会需要我们点击返回按钮或者返回首页按钮,跳转到首页模块,解决方案如下:

PaySuccess.m 响应返回的事件中

//创建一个消息对象
    NSNotification * notice = [NSNotification notificationWithName:@"BackHome" object:nil userInfo:nil];
    //发送消息
    [[NSNotificationCenter defaultCenter]postNotification:notice];
    [self.navigationController popToRootViewControllerAnimated:YES];

CarViewcontroller.m 中的处理

//获取通知中心单例对象
    NSNotificationCenter * center = [NSNotificationCenter defaultCenter];
    //添加当前类对象为一个观察者,name和object设置为nil,表示接收一切通知
    [center addObserver:self selector:@selector(backHome) name:@"BackHome" object:nil];
-(void)backHome {
    //注意index实际应用时位置,不要越界或者写一个不存在的
    self.tabBarController.selectedIndex = 0;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容