(iOS)点击cell推出现新界面

可能是以前比较菜,UITableVeiw点击cell的时候我会用switch 根据点击的row来判断点击的哪行然后初始化,

懒是程序猿的美德,我看一点都没错,我这些天在研究百度地图,然后我看到了一个非常有用的方法,就一下子吧我的一个个初始化的问题解决了,过来围观一下吧

举个例子

是这样的人家把所有的要推出来的ViewController名 写在数组里面了

_viewControllerArray = [[NSArray alloc]initWithObjects:

@"MapViewBaseDemoViewController",

@"MultiMapViewDemo",

@"MapViewDemoViewController",

nil];

然后在didSelectRow里面这样子

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

                UIViewController* viewController = nil;

                if (indexPath.row < 19 && indexPath.row != 12) {

                        //手敲版的

                         viewController = [[NSClassFromString([_viewControllerArray objectAtIndex:indexPath.row])  alloc]  init];

                 } else {

                      //stb(UIStoryboard)版的

                      viewController = [[UIStoryboard storyboardWithName:@"Storyboard" bundle:nil] instantiateViewControllerWithIdentifier:[_viewControllerArray objectAtIndex:indexPath.row]];

               }

             //设置返回按钮

              UIBarButtonItem *customLeftBarButtonItem = [[UIBarButtonItem alloc] init];

              customLeftBarButtonItem.title = @"返回";

              self.navigationItem.backBarButtonItem = customLeftBarButtonItem;

              [self.navigationController pushViewController:viewController animated:YES];

}

你可能感兴趣的:((iOS)点击cell推出现新界面)