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.pswp.cn/news/388367.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/388367.shtml
英文地址,請注明出處:http://en.pswp.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…