1。新建一个基于Navigation-based Application的工程。

2。修改原来的RootViewController.h,RootViewController.m,RootViewController.xib为MyTableViewController.h,MyTableViewController.m,MyTableViewController.xib。

3。点击MainVindow.xib,将Rot View Controller的class设置为:MyTableViewController。

4。新建文件:DetailViewController.m文件并选择自动生成.h与.xib文件,然后在DetailViewController.xib拖入一个map view控件。

5。代码:(控件与属性连接就省略了)

第一个页面的代码:

MyTableViewController.h

[cpp] view plaincopyprint?
  1. #import <UIKit/UIKit.h>
  2. @interface MyTableViewController : UITableViewController {
  3. NSMutableArray *listData;//表格第一部分的数据
  4. NSMutableArray * twolistData;//表格第二部分的数据
  5. }
  6. @property(nonatomic,retain) NSMutableArray *listData;
  7. @property(nonatomic,retain) NSMutableArray *twolistData;
  8. @end
#import <UIKit/UIKit.h>
@interface MyTableViewController : UITableViewController {
NSMutableArray *listData;//表格第一部分的数据
NSMutableArray * twolistData;//表格第二部分的数据
}
@property(nonatomic,retain) NSMutableArray *listData;
@property(nonatomic,retain) NSMutableArray *twolistData;
@end

MyTableViewController.m

[cpp] view plaincopyprint?
  1. #import "MyTableViewController.h"
  2. #import "DetailViewController.h"
  3. @implementation MyTableViewController
  4. @synthesize listData;
  5. @synthesize twolistData;
  6. #pragma mark -
  7. #pragma mark View lifecycle
  8. //设置标题和初始化表格数据
  9. - (void)viewDidLoad {
  10. [super viewDidLoad];
  11. listData = [[NSMutableArray alloc] initWithObjects:@"Beijing",@"Shanghai",@"Guangzhou",nil];
  12. twolistData = [[NSMutableArray alloc] initWithObjects:@"Changsha", nil];
  13. self.title = @"第一个页面";
  14. }
  15. #pragma mark -
  16. #pragma mark Table view data source
  17. // 设置表格为两个部分
  18. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  19. return 2;
  20. }
  21. //设置每个部分的标题
  22. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
  23. {
  24. NSString* secHeader = @"";
  25. if (section == 0)
  26. {
  27. secHeader = @"中国三大城市";
  28. }
  29. else if (section == 1)
  30. {
  31. secHeader = @"湖南省会";
  32. }
  33. return secHeader;
  34. }
  35. // 设置每个部分的显示行数
  36. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  37. if (section == 0) {
  38. return listData.count;
  39. }
  40. else if (section == 1) {
  41. return twolistData.count;
  42. }
  43. return 0;
  44. }
  45. // 设置行数据
  46. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  47. static NSString *CellIdentifier = @"Cell";
  48. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  49. if (cell == nil) {
  50. cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
  51. }
  52. if (indexPath.section == 0) {
  53. cell.textLabel.text = [listData objectAtIndex:indexPath.row];
  54. }
  55. else if(indexPath.section == 1){
  56. cell.textLabel.text = [twolistData objectAtIndex:indexPath.row];
  57. }
  58. return cell;
  59. }
  60. #pragma mark -
  61. #pragma mark Table view delegate
  62. //表格行点击事件
  63. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  64. NSString *selectedRow;
  65. if (indexPath.section == 0) {
  66. selectedRow = [listData objectAtIndex:indexPath.row];
  67. }else if(indexPath.section == 1){
  68. selectedRow = [twolistData objectAtIndex:indexPath.row];
  69. }
  70. DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
  71. detailViewController.selectedRow = selectedRow;
  72. [self.navigationController pushViewController:detailViewController animated:YES];
  73. [detailViewController release];
  74. }
  75. #pragma mark -
  76. #pragma mark Memory management
  77. - (void)didReceiveMemoryWarning {
  78. [super didReceiveMemoryWarning];
  79. }
  80. - (void)viewDidUnload {
  81. }
  82. - (void)dealloc {
  83. [listData release];
  84. [twolistData release];
  85. [super dealloc];
  86. }
  87. @end
#import "MyTableViewController.h"
#import "DetailViewController.h"
@implementation MyTableViewController
@synthesize listData;
@synthesize twolistData;
#pragma mark -
#pragma mark View lifecycle
//设置标题和初始化表格数据
- (void)viewDidLoad {
[super viewDidLoad];
listData = [[NSMutableArray alloc] initWithObjects:@"Beijing",@"Shanghai",@"Guangzhou",nil];
twolistData = [[NSMutableArray alloc] initWithObjects:@"Changsha", nil];
self.title = @"第一个页面";
}
#pragma mark -
#pragma mark Table view data source
// 设置表格为两个部分
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
//设置每个部分的标题
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
NSString* secHeader = @"";
if (section == 0)
{
secHeader = @"中国三大城市";
}
else if (section == 1)
{
secHeader = @"湖南省会";
}
return secHeader;
}
// 设置每个部分的显示行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == 0) {
return listData.count;
}
else if (section == 1) {
return twolistData.count;
}
return 0;
}
// 设置行数据
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
if (indexPath.section == 0) {
cell.textLabel.text = [listData objectAtIndex:indexPath.row];
}
else if(indexPath.section == 1){
cell.textLabel.text = [twolistData objectAtIndex:indexPath.row];
}
return cell;
}
#pragma mark -
#pragma mark Table view delegate
//表格行点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *selectedRow;
if (indexPath.section == 0) {
selectedRow = [listData objectAtIndex:indexPath.row];
}else if(indexPath.section == 1){
selectedRow = [twolistData objectAtIndex:indexPath.row];
}
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
detailViewController.selectedRow = selectedRow;
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
#pragma mark -
#pragma mark Memory management
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
}
- (void)dealloc {
[listData release];
[twolistData release];
[super dealloc];
}
@end

第二个页面的代码:

DetailViewController.h

[cpp] view plaincopyprint?
  1. #import <UIKit/UIKit.h>
  2. #import <Foundation/Foundation.h>
  3. @interface DetailViewController : UIViewController {
  4. NSString *selectedRow;//用来保存前一个页面传过来的参数
  5. IBOutlet UIWebView *webView;//浏览器控件
  6. }
  7. @property (nonatomic,retain) NSString *selectedRow;
  8. @property (nonatomic,retain) UIWebView *webView;
  9. @end
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@interface DetailViewController : UIViewController {
NSString *selectedRow;//用来保存前一个页面传过来的参数
IBOutlet UIWebView *webView;//浏览器控件
}
@property (nonatomic,retain) NSString *selectedRow;
@property (nonatomic,retain) UIWebView *webView;
@end

DetailViewController.m

[cpp] view plaincopyprint?
  1. #import "DetailViewController.h"
  2. @implementation DetailViewController
  3. @synthesize selectedRow,webView;
  4. //设置标题和根据传过来的参数打开google地图
  5. - (void)viewDidLoad {
  6. [super viewDidLoad];
  7. self.title = selectedRow;//设置标题
  8. NSString* addressText = selectedRow;
  9. addressText = [addressText stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding];
  10. NSString* urlText = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@",addressText];
  11. webView.userInteractionEnabled = true;
  12. [webView loadRequest:[[NSURLRequest alloc]  initWithURL:[[NSURL alloc] initWithString:urlText]]];//打开google地图
  13. }
  14. - (void)didReceiveMemoryWarning {
  15. [super didReceiveMemoryWarning];
  16. }
  17. - (void)viewDidUnload {
  18. [super viewDidUnload];
  19. }
  20. - (void)dealloc {
  21. [super dealloc];
  22. [selectedRow release];
  23. [webView release];
  24. }
  25. @end
#import "DetailViewController.h"
@implementation DetailViewController
@synthesize selectedRow,webView;
//设置标题和根据传过来的参数打开google地图
- (void)viewDidLoad {
[super viewDidLoad];
self.title = selectedRow;//设置标题
NSString* addressText = selectedRow;
addressText = [addressText stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding];
NSString* urlText = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@",addressText];
webView.userInteractionEnabled = true;
[webView loadRequest:[[NSURLRequest alloc]  initWithURL:[[NSURL alloc] initWithString:urlText]]];//打开google地图
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
[super viewDidUnload];
}
- (void)dealloc {
[super dealloc];
[selectedRow release];
[webView release];
}
@end

iphone UITableView及UIWebView的使用相关推荐

  1. [iPhone开发]UIWebview 嵌入 UITableview

    UIWebview 嵌入UITableview, 将UIWebview 加入到UITableview的cell里面,而且,将UIWebview 的高度设为内容的高度, 内容的高度,可以当UIWebvi ...

  2. iPhone SDK开发基础之iPhone程序框架

    总的来说iPhone程序有两类框架,一类是游戏框架,另一类是非游戏框架,这里介绍的是非游戏框架,即基于iPhone 用户界面标准控件的程序框架. 典型的iPhone程序包含一个Window和几个UIV ...

  3. 了解iPhone App特点及基本设计方法

    了解iPhone App特点及基本设计方法 本文介绍的是了解iPhone App特点及基本设计方法,很详细的介绍了设计方法,我们先来看内容. AD: 本文主要是来了解iPhone App特点及基本设计 ...

  4. 《iOS 8开发指南(第2版)》——第1章,第1.3节工欲善其事,必先利其器——搭建开发环境...

    本节书摘来自异步社区<iOS 8开发指南(第2版)>一书中的第1章,第1.1节1.3 工欲善其事,必先利其器--搭建开发环境,作者 管蕾,更多章节内容可以访问云栖社区"异步社区& ...

  5. UIScrollView点击StatusBar返回顶部失效的解决

    查看UIScrollView的头文件可以发现这样一段注释: // When the user taps the status bar, the scroll view beneath the touc ...

  6. iOS crash 问题分析汇总

    在这里插入图片描述 iOS crash 问题分析 iOS crash 常用分析工具 IOS 崩溃日志 iOS crash 原因分析 1.调用悬浮指针 2.数组越界访问 3.调用了未实现的方法 4.调用 ...

  7. iOS uiscrollView 嵌套 问题 的解决

    苹果官方文档里面提过,最好不要嵌套scrollView,特别提过UITableView和UIWebView,因为在滑动时,无法知道到底是希望superScrollView滑动还是subScrollVi ...

  8. 在Scrollview中使用AutoLayout

    AutoLayout 与 UIScrollView的相遇是一个不可避免的场景,像UITableView.UIWebView这些都是继承于UIScrollView的,关于它们的autolayout布局大 ...

  9. 将网页保存为webarchive文件的代码

    来自网络https://github.com/takebayashi/STWebArchiver 用于Mac电脑上的代码,可以将指定URL的网页保存为.webarchive 文件,iPhone上的UI ...

最新文章

  1. oracle增加数据时报没安装java_在linux上安装Oracle Developer Tools for VS Code
  2. cocos2d-x学习笔记03:绘制基本图元
  3. 多列布局——column-width
  4. boost使用split分割字符串
  5. some example of SAP odata annotation in metadata
  6. winform中listview选中整行_工作中常见的11个Excel难题,一次解决!
  7. python编程狮app题库_‎Python编程狮-零基础学Python App Storessa
  8. 粒子滤波随机采样算法
  9. 下载超星或读秀图书时,怎么搞定完整书签?
  10. 轮廓(查找和绘制轮廓、轮廓的表达与组织、轮廓的特性)
  11. Nginx网页优化(隐藏版本号,日志分割,更改进程数,网页压缩,防盗链详
  12. 小数除法竖式计算过程
  13. 字节跳动布局游戏,打算从腾讯的碗里“抢饭吃”?
  14. 武汉坚守第二十二天——谣言与辟谣与慌乱
  15. 洛谷 P1361 小猫爬山
  16. django模型层FQ查询,only,defer关键字,orm简单事务
  17. matlab如何查看眼图q值,详解:什么是眼图、眼图怎么看?
  18. 4668. 【NOIP2016提高A组模拟7.19】腐败
  19. shell脚本一步完成多层ssh跳转时的文件传输:Multi-layer scp
  20. 响应式设计和移动端优化:如何实现页面在不同设备上的适配和优化

热门文章

  1. 【C++ grammar】Enhancement for Type System (C++11 对类型系统的增强)
  2. strictmath_Java StrictMath sqrt()方法与示例
  3. 兰州交通大学C语言课程设计,兰州交通大学C语言课程设计报告(完整版).doc
  4. [Golang]计算一个文件的MD5值
  5. net-tools和ifconfig
  6. PyCharm和git安装教程
  7. 网络基础3-1(细谈IP协议头, 网络层,子网划分,路由选择,数据链路层,以太网帧格式,MAC地址,再谈ARP协议)
  8. leetcode283.移动零
  9. Epoll 的tcp通信代码(服务器+客户端)
  10. Linux下多线程模拟停车场停车