
1
|
Class class = NSClassFromString(self.arr[sender.tag - 100]);
|
对象转字符串
1
|
VC.navigationItem.title = NSStringFromClass([VC class]);
|
完整代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
- (void)viewDidLoad { [super viewDidLoad]; self.arr = @[@"ViewController1", @"ViewController2", @"ViewController3", @"ViewController4"]; } - (IBAction)buttonAction:(UIButton *)sender { NSLog(@"--%@--", [NSString stringWithFormat:@"%ld", sender.tag]); //字符串 转 对象 Class class = NSClassFromString(self.arr[sender.tag - 100]); UIViewController *VC = [(UIViewController *)[class alloc] init]; VC.view.backgroundColor = [UIColor whiteColor]; //对象 转 字符串 VC.navigationItem.title = NSStringFromClass([VC class]); [self.navigationController pushViewController:VC animated:YES]; }
|
原文链接: http://blog.csdn.net/zhz459880251/article/details/50477814
近期评论