从AppDelegate模态或者push到某个页面
来源:互联网 发布:网络主播行业分析 编辑:程序博客网 时间:2024/06/05 02:42
模态到指定页面
FirstViewController
FirstViewController *ffVC =[[FirstViewControlleralloc]init];
UINavigationController *pushNav = [[UINavigationControlleralloc]initWithRootViewController:ffVC];
[self.window.rootViewControllerpresentViewController:pushNavanimated:YEScompletion:nil];
push 到 FirstViewController
//push
UINavigationController *_nav = (UINavigationController*) (self.window.rootViewController);
FirstViewController *_vc = [[FirstViewControlleralloc]init];
[_nav pushViewController:_vcanimated:YES];
通知时要根据字典返回字段判断跳转到指定的控制器
FirstViewController
判断页面是push还是模态进入当前页面
- (void)enterType{
NSArray *viewcontrollers=self.navigationController.viewControllers;
if (viewcontrollers.count>1) {
if ([viewcontrollersobjectAtIndex:viewcontrollers.count-1]==self) {
//push方式
NSLog(@"ppppppuuuusssshh");
}
}
else{
//模态方式
NSLog(@"mmmmmmmdddddaaaa--模态");
}
}
最近看到有利用runtime 万能跳转:
#import "AppDelegate.h"
#import <objc/runtime.h> //引入runtime
//加载完成调用
- (void)test
{
// 这个规则肯定事先跟服务端沟通好,跳转对应的界面需要对应的参数
NSDictionary *userInfo =@{
@"class":@"HSFeedsViewController",
@"property":@{
@"ID":@"123",
@"type":@"12"
}
};
[selfpush:userInfo];
}
#pragma mark 接收推送消息
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
// 这个规则肯定事先跟服务端沟通好,跳转对应的界面需要对应的参数
//NSDictionary *userInfo = @{
// @"class": @"HSFeedsViewController",
// @"property": @{
// @"ID": @"123",
// @"type": @"12"
// }
// };
[selfpush:userInfo];
}
/**
* 跳转界面
*/
- (void)push:(NSDictionary *)params
{
// 类名
NSString *class =[NSStringstringWithFormat:@"%@", params[@"class"]];
constchar *className = [classcStringUsingEncoding:NSASCIIStringEncoding];
// 从一个字串返回一个类
Class newClass =objc_getClass(className);
if (!newClass)
{
// 创建一个类
Class superClass = [NSObjectclass];
newClass = objc_allocateClassPair(superClass, className,0);
// 注册你创建的这个类
objc_registerClassPair(newClass);
}
// 创建对象
id instance = [[newClassalloc]init];
NSDictionary *propertys = params[@"property"];
[propertys enumerateKeysAndObjectsUsingBlock:^(id key,id obj,BOOL *stop) {
// 检测这个对象是否存在该属性
if ([selfcheckIsExistPropertyWithInstance:instanceverifyPropertyName:key]) {
// 利用kvc赋值
[instance setValue:objforKey:key];
}
}];
// 获取导航控制器
UITabBarController *tabVC = (UITabBarController *)self.window.rootViewController;
UINavigationController *pushClassStance = (UINavigationController *)tabVC.viewControllers[tabVC.selectedIndex];
// 跳转到对应的控制器
[pushClassStance pushViewController:instanceanimated:YES];
}
/**
* 检测对象是否存在该属性
*/
- (BOOL)checkIsExistPropertyWithInstance:(id)instance verifyPropertyName:(NSString *)verifyPropertyName
{
unsignedint outCount, i;
// 获取对象里的属性列表
objc_property_t * properties =class_copyPropertyList([instance
class], &outCount);
for (i =0; i < outCount; i++) {
objc_property_t property =properties[i];
// 属性名转成字符串
NSString *propertyName = [[NSStringalloc]initWithCString:property_getName(property)encoding:NSUTF8StringEncoding];
// 判断该属性是否存在
if ([propertyNameisEqualToString:verifyPropertyName]) {
free(properties);
returnYES;
}
}
free(properties);
returnNO;
}
- 从AppDelegate模态或者push到某个页面
- iOS 收到推送从AppDelegate push 到详细页面
- IOS 在AppDelegate 页面中push到另一个页面
- 从Appdelegate传值到其他页面
- 从当前页面跳转到其他页面的某个地方
- 如何从模态视图push到下一个ViewController
- iOS 从AppDelegate中跳转指定页面
- Android-从通讯录导入某个联系人到页面
- 模态弹出的页面push或pop到其他页面
- git版本控制从某个版本恢复到之前或者之后的版本的方法
- 模态跳转和push跳转到公共页面如何返回
- 从自建页面跳转到标准订单或者BP页面的例子
- PHP 跳转到某个页面
- 动画push推送到另一个页面
- 从 Push-Action 到 Encourage-Response
- struts2错误java.lang.NoSuchMethodException: ...XXXAction.create()或者从页面到Action时找不到Action
- 从jsp或者aspx这种动态页面获取图片并保存到本地
- Appdelegate里面跳转页面
- 自定义漂亮的toast
- Kotlin 之hello world篇
- web安全——CSRF漏洞原理和解决方案
- |poj 1523|割顶|[HAOI2015]SPF
- 反射
- 从AppDelegate模态或者push到某个页面
- JavaSE进阶(一)隐晦的int溢出
- .NET面试问题(1)
- 浅谈函数的调用和栈帧的创建和销毁
- eclipse安装svn插件的两种方式
- 集群与负载均衡系列(6)——消息队列之rabbitMQ+spring-boot+spring amqp发送可靠的消息
- 欢迎使用CSDN-markdown编辑器
- C# Winform 显示Gif动图
- php Phar 打包