国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

iOS-runtime-根據(jù)類名推送到任意控制器,且實(shí)現(xiàn)屬性傳值

2019-11-14 18:21:52
字體:
供稿:網(wǎng)友
////  WJRuntime.m//  RuntimeSkip////  Created by tqh on 15/9/8.//  Copyright (c) 2015年 tqh. All rights reserved.//#import "WJRuntime.h"#import <objc/runtime.h>@implementation WJRuntime//runtime跳轉(zhuǎn)+ (void)runtimePush:(NSString *)vcName dic:(NSDictionary *)dic nav:(UINavigationController *)nav {    //類名(對象名)        NSString *class = vcName;        const char *className = [class cStringUsingEncoding:NSASCIIStringEncoding];    Class newClass = objc_getClass(className);    if (!newClass) {        //創(chuàng)建一個類        Class superClass = [NSObject class];        newClass = objc_allocateClassPair(superClass, className, 0);        //注冊你創(chuàng)建的這個類        objc_registerClassPair(newClass);    }    // 創(chuàng)建對象(寫到這里已經(jīng)可以進(jìn)行隨機(jī)頁面跳轉(zhuǎn)了)    id instance = [[newClass alloc] init];        //下面是傳值--------------        [dic enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {        if ([self checkIsExistPRopertyWithInstance:instance verifyPropertyName:key]) {            //kvc給屬性賦值                        [instance setValue:obj forKey:key];        }else {            NSLog(@"不包含key=%@的屬性",key);        }    }];    [nav 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];        //  屬性名轉(zhuǎn)成字符串        NSString *propertyName = [[NSString alloc] initWithCString:property_getName(property) encoding:NSUTF8StringEncoding];        // 判斷該屬性是否存在        if ([propertyName isEqualToString:verifyPropertyName]) {            free(properties);            return YES;        }    }    free(properties);        return NO;}@end

 

 

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 哈巴河县| 施秉县| 莱阳市| 土默特左旗| 潮州市| 荔波县| 天台县| 常宁市| 南溪县| 大方县| 会泽县| 外汇| 正宁县| 水富县| 原阳县| 闸北区| 惠安县| 凤城市| 山阳县| 延津县| 刚察县| 雅安市| 黔东| 兰考县| 聂拉木县| 阳曲县| 将乐县| 马尔康县| 大安市| 漳浦县| 铁力市| 亳州市| 武城县| 天水市| 禄劝| 怀化市| 奎屯市| 普兰店市| 格尔木市| 榆树市| 嘉荫县|