iphone UITableView及UIWebView的使用

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.   
  3. @interface MyTableViewController : UITableViewController {  
  4.       
  5.     NSMutableArray *listData;//表格第一部分的数据   
  6.     NSMutableArray * twolistData;//表格第二部分的数据   
  7. }  
  8.   
  9. @property(nonatomic,retain) NSMutableArray *listData;  
  10. @property(nonatomic,retain) NSMutableArray *twolistData;  
  11.   
  12. @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.   
  3. #import "DetailViewController.h"   
  4.   
  5. @implementation MyTableViewController  
  6.   
  7. @synthesize listData;  
  8. @synthesize twolistData;  
  9.   
  10. #pragma mark -   
  11. #pragma mark View lifecycle   
  12.   
  13. //设置标题和初始化表格数据   
  14. - (void)viewDidLoad {  
  15.     [super viewDidLoad];  
  16.       
  17.     listData = [[NSMutableArray alloc] initWithObjects:@"Beijing",@"Shanghai",@"Guangzhou",nil];  
  18.       
  19.     twolistData = [[NSMutableArray alloc] initWithObjects:@"Changsha", nil];  
  20.       
  21.     self.title = @"第一个页面";  
  22.       
  23. }  
  24. #pragma mark -   
  25. #pragma mark Table view data source   
  26.   
  27. // 设置表格为两个部分   
  28. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {  
  29.     return 2;  
  30. }  
  31. //设置每个部分的标题   
  32. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section  
  33. {  
  34.     NSString* secHeader = @"";  
  35.       
  36.     if (section == 0)  
  37.     {  
  38.         secHeader = @"中国三大城市";  
  39.     }  
  40.     else if (section == 1)  
  41.     {  
  42.         secHeader = @"湖南省会";  
  43.     }  
  44.     return secHeader;  
  45. }  
  46.   
  47. // 设置每个部分的显示行数   
  48. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {  
  49.     if (section == 0) {  
  50.         return listData.count;  
  51.     }  
  52.     else if (section == 1) {  
  53.         return twolistData.count;  
  54.     }  
  55.     return 0;  
  56. }  
  57.   
  58.   
  59. // 设置行数据   
  60. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {  
  61.       
  62.     static NSString *CellIdentifier = @"Cell";  
  63.       
  64.     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];  
  65.     if (cell == nil) {  
  66.         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];  
  67.     }  
  68.       
  69.     if (indexPath.section == 0) {  
  70.         cell.textLabel.text = [listData objectAtIndex:indexPath.row];  
  71.     }  
  72.     else if(indexPath.section == 1){  
  73.         cell.textLabel.text = [twolistData objectAtIndex:indexPath.row];  
  74.     }  
  75.       
  76.       
  77.     return cell;  
  78. }  
  79.   
  80. #pragma mark -   
  81. #pragma mark Table view delegate   
  82. //表格行点击事件   
  83. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {  
  84.     NSString *selectedRow;  
  85.     if (indexPath.section == 0) {  
  86.         selectedRow = [listData objectAtIndex:indexPath.row];  
  87.     }else if(indexPath.section == 1){  
  88.         selectedRow = [twolistData objectAtIndex:indexPath.row];  
  89.     }  
  90.       
  91.       
  92.     DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];  
  93.       
  94.       
  95.     detailViewController.selectedRow = selectedRow;  
  96.       
  97.     [self.navigationController pushViewController:detailViewController animated:YES];  
  98.       
  99.     [detailViewController release];  
  100. }  
  101.   
  102. #pragma mark -   
  103. #pragma mark Memory management   
  104.   
  105. - (void)didReceiveMemoryWarning {  
  106.     [super didReceiveMemoryWarning];  
  107.       
  108. }  
  109. - (void)viewDidUnload {  
  110.       
  111. }  
  112.   
  113. - (void)dealloc {  
  114.     [listData release];  
  115.     [twolistData release];  
  116.     [super dealloc];  
  117. }  
  118.   
  119.   
  120. @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.   
  3. #import <Foundation/Foundation.h>   
  4.   
  5.   
  6. @interface DetailViewController : UIViewController {  
  7.       
  8.     NSString *selectedRow;//用来保存前一个页面传过来的参数   
  9.       
  10.     IBOutlet UIWebView *webView;//浏览器控件   
  11.       
  12. }  
  13.   
  14. @property (nonatomic,retain) NSString *selectedRow;  
  15. @property (nonatomic,retain) UIWebView *webView;  
  16.   
  17. @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.   
  3. @implementation DetailViewController  
  4.   
  5. @synthesize selectedRow,webView;  
  6.   
  7. //设置标题和根据传过来的参数打开google地图   
  8. - (void)viewDidLoad {  
  9.     [super viewDidLoad];  
  10.       
  11.     self.title = selectedRow;//设置标题   
  12.       
  13.     NSString* addressText = selectedRow;  
  14.       
  15.     addressText = [addressText stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding];  
  16.       
  17.     NSString* urlText = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@",addressText];  
  18.       
  19.     webView.userInteractionEnabled = true;  
  20.       
  21.     [webView loadRequest:[[NSURLRequest alloc]  initWithURL:[[NSURL alloc] initWithString:urlText]]];//打开google地图   
  22.       
  23. }  
  24. - (void)didReceiveMemoryWarning {  
  25.     [super didReceiveMemoryWarning];  
  26. }  
  27.   
  28. - (void)viewDidUnload {  
  29.     [super viewDidUnload];  
  30. }  
  31.   
  32. - (void)dealloc {  
  33.     [super dealloc];  
  34.     [selectedRow release];  
  35.     [webView release];  
  36.       
  37. }  
  38. @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




本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/388367.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

python 的datetime模块使用

1.datetime模块主要是5个类 date #日期类 年月日 datetime.date(year,month,day) time #时间类 时分秒 datetime.time(hour,minute,second,microsecond,tzoninfo),返回18:29:30 datetime #日期时间类 datetime(year, month, day[, hour[, minute[, second[, microsecond[,tzinf…

物联网数据可视化_激发好奇心:数据可视化如何增强博物馆体验

物联网数据可视化When I was living in Paris at the beginning of this year, I went to a minimum of three museums a week. While this luxury was made possible by the combination of an ICOM card and unemployment, it was founded on a passion for museums. Looking…

计算机公开课教学反思,语文公开课教学反思

语文公开课教学反思引导语&#xff1a; 在语文的公开课结束后&#xff0c;教师们在教学 有哪些需要反思的呢?接下来是yjbys小编为大家带来的关于语文公开课教学反思&#xff0c;希望会给大家带来帮助。篇一&#xff1a;语文公开课教学反思今天早上&#xff0c;我上了一节语文…

中国连续十年成马来西亚最大贸易伙伴

中新社吉隆坡1月30日电 (记者 陈悦)马来西亚国际贸易和工业部30日发布的2018年马来西亚贸易报告显示&#xff0c;2018年马来西亚与中国的贸易额约为3138.1亿林吉特(马来西亚货币&#xff0c;约合774亿美元)&#xff0c;较上年同期增长8.1%&#xff0c;约占马来西亚对外贸易总额…

Iphone NSMutableArray,NSMutableDictionary AND 动态添加按钮

一.NSMutableDictionary NSMutableDictionary * tags&#xff1b; 1.NSMutableDictionary 添加内容&#xff1a; [tags setValue:xxx forKey :xxx]; 2.NSMutableDictionary 遍历&#xff1a; for(NSString * title in tags){ //其中得到的title是key } 3.NSMutableD…

bzoj2938: [Poi2000]病毒

被Star_Feel大爷带着做题 明显大力AC机然后找环 本来我一开始想的是先去有另一个病毒为前缀的病毒&#xff0c;结果今天早上写的时候偷懒没写 结果跳fail的时候会跳到中间。。。无语&#xff0c;Star_Feel大爷叫我son或一下now和fail就过了 还有神仙是直接把fail接到儿子的更流…

bigquery数据类型_将BigQuery与TB数据一起使用后的成本和性能课程

bigquery数据类型I’ve used BigQuery every day with small and big datasets querying tables, views, and materialized views. During this time I’ve learned some things, I would have liked to know since the beginning. The goal of this article is to give you so…

中国计算机学科建设,计算机学科建设战略研讨会暨“十四五”规划务虚会召开...

4月15日下午&#xff0c;信息学院计算机系举办了计算机科学与技术学科建设战略研讨会暨“十四五”规划务虚会。本次会议的主旨是借第五轮学科评估的契机&#xff0c;总结计算机学科发展的优劣势&#xff0c;在强调保持优势的同时&#xff0c;更着眼于短板和不足&#xff0c;在未…

iphone开发如何隐藏各种bar

转载至&#xff1a;http://blog.csdn.net/riveram/article/details/7291142 状态条StatusBar [cpp] view plaincopyprint?[UIApplication sharedApplication].statusBarHidden YES; [UIApplication sharedApplication].statusBarHidden YES; 导航条NavigationBar [cpp] v…

Swift5.1 语言指南(九) 闭包

★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号&#xff1a;山青咏芝&#xff08;shanqingyongzhi&#xff09;➤博客园地址&#xff1a;山青咏芝&#xff08;https://www.cnblogs.com/strengthen/&#xff09;➤GitHub地址&a…

服务器被攻击怎么修改,服务器一直被攻击怎么办?

原标题&#xff1a;服务器一直被攻击怎么办&#xff1f;有很多人问说&#xff0c;网站一直被攻击&#xff0c;什么被挂马&#xff0c;什么被黑&#xff0c;每天一早打开网站&#xff0c;总是会出现各种各样的问题&#xff0c;这着实让站长们揪心。从修改服务器管理账号开始&…

脚本 api_从脚本到预测API

脚本 apiThis is the continuation of my previous article:这是我上一篇文章的延续&#xff1a; From Jupyter Notebook To Scripts从Jupyter Notebook到脚本 Last time we discussed how to convert Jupyter Notebook to scripts, together with all sorts of basic engine…

Iphone代码创建视图

要想以编程的方式创建视图&#xff0c;需要使用视图控制器中定义的viewDidLoad方法&#xff0c;只有在运行期间生成UI时才需要实现该方法。 在此只贴出viewDidLoad方法的代码&#xff0c;因为只需要在这个方法里面编写代码&#xff1a; [cpp] view plaincopyprint?- (void)vi…

聊聊flink Table的OrderBy及Limit

序 本文主要研究一下flink Table的OrderBy及Limit 实例 Table in tableEnv.fromDataSet(ds, "a, b, c"); Table result in.orderBy("a.asc");Table in tableEnv.fromDataSet(ds, "a, b, c");// returns the first 5 records from the sorted …

binary masks_Python中的Masks概念

binary masksAll men are sculptors, constantly chipping away the unwanted parts of their lives, trying to create their idea of a masterpiece … Eddie Murphy所有的人都是雕塑家&#xff0c;不断地消除生活中不必要的部分&#xff0c;试图建立自己的杰作理念……埃迪墨…

css+沿正方形旋转,CSS3+SVG+JS 正方形沿着正方本中轴移动翻转的动画

CSS语言&#xff1a;CSSSCSS确定* {margin: 0;padding: 0;fill: currentColor;vector-effect: non-scaling-stroke;}html {overflow: hidden;}body {display: flex;flex-direction: column;margin: 0;min-width: 10em;height: 100vh;}body > svg,body > input,body > …

Iphone在ScrollView下点击TextField使文本筐不被键盘遮住

1.拖一个Scroll View视图填充View窗口&#xff0c;将Scroll View视图拖大一些&#xff0c;使其超出屏幕。 2.向Scroll View拖&#xff08;添加&#xff09;多个Label视图和Text View视图。 3.在.h头文件中添加如下代码&#xff1a; [cpp] view plaincopyprint?#import <U…

两高发布司法解释 依法严惩涉地下钱庄犯罪

新华社北京1月31日电&#xff08;记者丁小溪&#xff09;最高人民法院、最高人民检察院31日联合发布关于办理非法从事资金支付结算业务、非法买卖外汇刑事案件适用法律若干问题的解释&#xff0c;旨在依法惩治非法从事资金支付结算业务、非法买卖外汇犯罪活动&#xff0c;维护金…

python 仪表盘_如何使用Python刮除仪表板

python 仪表盘Dashboard scraping is a useful skill to have when the only way to interact with the data you need is through a dashboard. We’re going to learn how to scrape data from a dashboard using the Selenium and Beautiful Soup packages in Python. The S…

VS2015 定时服务及控制端

一. 服务端 如下图—新建项目—经典桌面—Windows服务—起名svrr2. 打到server1 改名为svrExecSqlInsert 右击对应的设计界面&#xff0c;添加安装服务目录结构如图 3. svrExecSqlInsert里有打到OnStart()方法开始写代码如下 /// <summary>/// 服务开启操作/// </su…