iOS 万能跳转界面方法 (runtime实用篇一)
来源:互联网 发布:如何检查网络是否正常 编辑:程序博客网 时间:2024/04/30 08:53
@interface HSFeedsViewController : UIViewController// 注:根据下面的两个属性,可以从服务器获取对应的频道列表数据/** 频道ID */@property (nonatomic, copy) NSString *ID;/** 频道type */@property (nonatomic, copy) NSString *type;@end
跳转界面- (void)push:(NSDictionary *)params{ // 类名 NSString *class =[NSString stringWithFormat:@"%@", params[@"class"]]; const char *className = [class cStringUsingEncoding:NSASCIIStringEncoding]; // 从一个字串返回一个类 Class newClass = objc_getClass(className); if (!newClass) { // 创建一个类 Class superClass = [NSObject class]; newClass = objc_allocateClassPair(superClass, className, 0); // 注册你创建的这个类 objc_registerClassPair(newClass); } // 创建对象 id instance = [[newClass alloc] init]; // 对该对象赋值属性 NSDictionary * propertys = params[@"property"]; [propertys enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { // 检测这个对象是否存在该属性 if ([self checkIsExistPropertyWithInstance:instance verifyPropertyName:key]) { // 利用kvc赋值 [instance setValue:obj forKey:key]; } }]; // 获取导航控制器 UITabBarController *tabVC = (UITabBarController *)self.window.rootViewController; UINavigationController *pushClassStance = (UINavigationController *)tabVC.viewControllers[tabVC.selectedIndex]; // 跳转到对应的控制器 [pushClassStance pushViewController:instance animated:YES];}
- (BOOL)checkIsExistPropertyWithInstance:(id)instance verifyPropertyName:(NSString *)verifyPropertyName{ unsigned int 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 = [[NSString alloc] initWithCString:property_getName(property) encoding:NSUTF8StringEncoding]; // 判断该属性是否存在 if ([propertyName isEqualToString:verifyPropertyName]) { free(properties); return YES; } } free(properties); return NO;}
0 0
- iOS 万能跳转界面方法(runtime实用篇一)
- iOS 万能跳转界面方法 (runtime实用篇一)
- iOS 万能跳转界面方法 (runtime实用篇一)
- iOS 万能跳转界面方法 (runtime实用篇一)
- iOS 万能跳转界面方法 (runtime实用篇一)
- iOS 万能跳转界面方法 (runtime实用篇一)
- iOS 万能跳转界面方法 (runtime实用篇一)
- iOS 万能跳转界面方法 (runtime实用篇一)
- iOS 万能跳转界面方法(runtime实用篇一)
- iOS 万能跳转界面方法 (runtime实用篇一)
- iOS 万能跳转界面方法 (runtime实用篇一)
- iOS 万能跳转界面方法 (runtime实用篇一)
- iOS 万能跳转界面方法 (runtime实用篇一)
- iOS 万能跳转界面方法 (runtime实用篇一)
- iOS 万能跳转界面方法 (runtime实用篇一)
- iOS 万能跳转界面方法 (runtime实用篇一)
- iOS 万能跳转界面方法 (runtime实用篇一)
- iOS 万能跳转界面方法 (runtime实用篇一)
- 【RSA】求两个2^512左右的大素数
- 写个OKHttpUtils
- SQLiteDatabase 自带添加、删除、更新、查询的操作方
- HTML5学习(五)—3
- 给 Android 开发者的 RxJava 详解
- iOS 万能跳转界面方法 (runtime实用篇一)
- Mysql 常用函数总结(字符串操作函数)
- linux常用命令(二)
- Android弹出选项框及指示箭头动画选择
- JavaScript资源大全中文版(Awesome最新版)
- MFC中串口类的使用
- Install boost on ubuntu
- iOS富文本编辑器之更"优雅的"实现方法
- oracle收集表的统计信息