1、跳转方法:
//ViewController为要跳转的界面
id viewController = [[NSClassFromString(@"ViewController")alloc]init];
//判断urlString命名的字符串是否存在,如果不存在还进行传值会导致崩溃所以需要进行判断
if ([self checkIsExistValue:viewController andStringName:@"urlString"]) {
//urlString是NSString为ViewController创建的字符串,此为传值方法
[viewController setValue:@"https://www.baidu.com" forKey:@"urlString"];
}
[self.navigationController pushViewController:viewController animated:YES];
2、判断是否存在此字符串
- (BOOL)checkIsExistValue:(id)viewController andStringName:(NSString *)string
{
unsigned int count = 0;
// 获取对象里的属性列表
objc_property_t * properties = class_copyPropertyList([viewController class], &count);
for (int i = 0; i < count; i ++) {
objc_property_t property = properties[i];
// 属性名转成字符串
NSString * propertyName = [[NSString alloc]initWithCString:property_getName(property) encoding:NSUTF8StringEncoding];
// 判断该属性是否存在
if ([propertyName isEqualToString:string]) {
return YES;
}
}
free(properties);
return NO;
}