一个页面内要跳转不同的控制器,如个人中心页面
2015-11-13 10:16
375 查看
在百度地图的学习过程中,发现里面有一个不错的方法,怎么实现的呢?来分享一下!
- (void)viewDidLoad
{
[super viewDidLoad];
_demoNameArray = [[NSArray alloc]initWithObjects:
@"基本地图功能-MapViewBaseDemo",
@"多地图使用功能-MultiMapViewDemo",
@"图层展示功能-MapViewDemo",
@"地图操作功能-MapViewControlDemo",
@"UI控制功能-MapViewUISettingDemo",
@"定位功能-LocationDemo",
nil];
_viewControllerTitleArray = [[NSArray alloc]initWithObjects:
@"基本地图功能",
@"多地图使用功能",
@"图层展示功能",
@"地图操作功能",
nil];
_viewControllerArray = [[NSArray alloc]initWithObjects:
@"MapViewBaseDemoViewController",
@"MultiMapViewDemo",
@"MapViewDemoViewController",
nil];
self.title = [NSString stringWithFormat: @"欢迎使用百度地图iOS SDK %@", BMKGetMapApiVersion()];
//适配ios7
if( ([[[UIDevice currentDevice] systemVersion] doubleValue]>=7.0))
{
self.navigationController.navigationBar.translucent = NO;
}
}
#pragma mark -
#pragma mark Table view data source
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return _demoNameArray.count;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"BaiduMapApiDemoCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [_demoNameArray objectAtIndex:indexPath.row];
return cell;
}
#pragma mark -
#pragma mark Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIViewController* viewController = [[NSClassFromString([_viewControllerArray objectAtIndex:indexPath.row]) alloc] init];
viewController.title = [_viewControllerTitleArray objectAtIndex:indexPath.row];
UIBarButtonItem *customLeftBarButtonItem = [[UIBarButtonItem alloc] init];
customLeftBarButtonItem.title = @"返回";
self.navigationItem.backBarButtonItem = customLeftBarButtonItem;
[self.navigationController pushViewController:viewController animated:YES];
}
数组内有的随意写,不要见怪哦,重点在下面放大招了!! !
- (void)viewDidLoad
{
[super viewDidLoad];
_demoNameArray = [[NSArray alloc]initWithObjects:
@"基本地图功能-MapViewBaseDemo",
@"多地图使用功能-MultiMapViewDemo",
@"图层展示功能-MapViewDemo",
@"地图操作功能-MapViewControlDemo",
@"UI控制功能-MapViewUISettingDemo",
@"定位功能-LocationDemo",
nil];
_viewControllerTitleArray = [[NSArray alloc]initWithObjects:
@"基本地图功能",
@"多地图使用功能",
@"图层展示功能",
@"地图操作功能",
nil];
_viewControllerArray = [[NSArray alloc]initWithObjects:
@"MapViewBaseDemoViewController",
@"MultiMapViewDemo",
@"MapViewDemoViewController",
nil];
self.title = [NSString stringWithFormat: @"欢迎使用百度地图iOS SDK %@", BMKGetMapApiVersion()];
//适配ios7
if( ([[[UIDevice currentDevice] systemVersion] doubleValue]>=7.0))
{
self.navigationController.navigationBar.translucent = NO;
}
}
#pragma mark -
#pragma mark Table view data source
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return _demoNameArray.count;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"BaiduMapApiDemoCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [_demoNameArray objectAtIndex:indexPath.row];
return cell;
}
#pragma mark -
#pragma mark Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIViewController* viewController = [[NSClassFromString([_viewControllerArray objectAtIndex:indexPath.row]) alloc] init];
viewController.title = [_viewControllerTitleArray objectAtIndex:indexPath.row];
UIBarButtonItem *customLeftBarButtonItem = [[UIBarButtonItem alloc] init];
customLeftBarButtonItem.title = @"返回";
self.navigationItem.backBarButtonItem = customLeftBarButtonItem;
[self.navigationController pushViewController:viewController animated:YES];
}
数组内有的随意写,不要见怪哦,重点在下面放大招了!! !
相关文章推荐
- 未来视频会议技术发展趋势
- 我对推荐评测指标的理解
- 自定义事件 对事件需要好好研究一下
- 用MVP架构开发Android应用
- Eclipse远程调试Java程序
- pthread_create用法 http://blog.csdn.net/tommy_wxie/article/details/8545253
- Windows今日补丁
- #include与#import
- 随笔添加测试
- Eclipse远程调试Java程序
- 《从零开始学Swift》学习笔记(Day 35)——会使用下标吗?
- 秒杀系统架构设计
- Sublime Text 2/3 Reveal in finder 快捷键/shortcut
- jQuery EasyUI使用教程之创建可折叠面板
- <android5.0>之dialog的使用
- 白盒测试的六种覆盖方式
- dubbo 学习总结
- Java:类与继承
- Spring+Struts+Ibatis的配置
- Exception