成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

iPhone開發 UITableView代碼實現實例

移動開發 iOS
本文介紹的iPhone開發 UITableView代碼實現實例,主要介紹了UITableView的使用方法,我們先來看內容。

iPhone開發 UITableView代碼實現實例是本文要介紹的內容,介紹了UITableView的基本操作,以小實例實現,我們來看內容。
 
1、前題條件

1.1 UITableView不能直接加載到窗體中,窗體中首先要加載一個UIView控件,然后才可以添加UITableView

1.2 UITableView需要繼續兩個協議<UITableViewDelegate,UITableViewDataSource>

兩個協議的方法為:

--行的數量:

  1. -(NSInteger) tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section   
  2. {  
  3.  return [tableArray count];  
  4. }  
  5.  
  6. --行的定義  
  7.  
  8. -(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath  
  9. {  
  10.  static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";  
  11.    
  12.     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:  
  13.                              SimpleTableIdentifier];  
  14.     if (cell == nil)  
  15.  {  
  16.   //默認樣式  
  17.   cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault  
  18.                                    reuseIdentifier: SimpleTableIdentifier] autorelease];  
  19.  }  
  20.  //文字的設置  
  21.  NSUInteger row=[indexPath row];  
  22.  cell.textLabel.text=[tableArray objectAtIndex:row];  
  23.  return cell;  

2、添加UIView

  1.  UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320,260)];  
  2. //自定識別頭及高度  
  3.  view.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHeight;  
  4.  view.backgroundColor = [UIColor blueColor];  
  5. //將view添加到主窗體  
  6. [self.view addSubview:view]; 

3、添加UITableView

  1. UITableView  *table1=[[UITableView alloc] initWithFrame:CGRectMake(0, 0.00, 300, 250)];  
  2.  table1.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHeight;  
  3. table1.backgroundColor=[UIColor redColor];  
  4. //添加到view窗體上  
  5. [view addSubview:table1];  
  6.  table1.delegate=self;  
  7.  table1.dataSource=self

4、取消點擊動畫

  1. [tableView deselectRowAtIndexPath:indexPath animated:YES]; 

5、滾動路徑標識,直至指數連續接收器在屏幕上的特定位置

  1. - (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:
  2. (BOOL)animated Parameters   

indexPath

索引路徑標識在其行的索引,其部分指標表視圖行。

scrollPosition

 一個常數,在接收標識表查看行(上,中,下)的相對位置滾動時結束。

animated

是如果你要動畫在位置改變,沒有是否應立即生效。

實例代碼:

  1. float height = 216.0;  
  2. CGRect frame = m_pTableView.frame;  
  3. frame.size = CGSizeMake(frame.size.width, frame.size.height - height);  
  4. [UIView beginAnimations:@"Curl"context:nil];//動畫開始     
  5. [UIView setAnimationDuration:0.30];     
  6. [UIView setAnimationDelegate:self];    
  7. [m_pTableView setFrame:frame];    
  8. [m_pTableView scrollToRowAtIndexPath:selectedIndexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];  
  9. [UIView commitAnimations];  

6、獲取選中的列,如圖所示:

iPhone開發 UITableView代碼實現實例

代碼如下:

  1. for (NSInteger i = 0; i < [[peopleTableView visibleCells] count]; i++)   
  2. {  
  3. UITableViewCell *cell = [[peopleTableView visibleCells] objectAtIndex:i];  
  4. if (cell.accessoryType == UITableViewCellAccessoryCheckmark) //將勾選的人員添加到列表中  
  5. {  
  6. Item *item = (Item *)[NextPeopleList.SelectList objectAtIndex:i];  
  7. [peopleList addObject:item];  
  8. isCheck = TRUE;  
  9. }  

7、Cell將要顯示時事件

  1. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath  
  2. {  
  3. if (indexPath.row % 2 == 0) {  
  4. cell.backgroundColor = DarkColor;  
  5. }else {  
  6. cell.backgroundColor = LightColor;  

小結:iPhone開發 UITableView代碼實現實例的內容介紹完了,希望本文對你有所幫助!

責任編輯:zhaolei 來源: 互聯網
相關推薦

2011-07-28 10:11:54

iPhone開發 備忘

2011-08-08 10:42:46

iPhone UITableVie 分頁

2011-07-27 11:14:37

iPhone UITableVie

2011-08-15 13:44:07

iPhone開發UITableView

2011-07-25 18:02:51

iPhone LibFetion 移植

2011-08-08 16:56:44

iPhone 字符處理 視圖

2011-08-19 10:01:09

iPhone應用SqliteUITableView

2011-08-02 17:14:41

iPhone應用 UITableVie

2011-07-25 14:44:41

iPhone iPhone開發 截屏

2011-07-22 17:24:46

iPhone 視圖

2011-08-01 13:13:19

iPhone開發 圖片

2011-08-15 11:23:41

iPhone開發循環滾動UIScrollVie

2009-07-22 11:27:36

iBATIS模糊查詢

2009-09-01 16:59:25

C#畫直線

2009-08-17 14:41:47

C#進度條實現

2009-08-27 18:09:49

C#接口的實現

2009-09-01 13:59:01

C#操作Excel

2009-09-09 12:55:59

C# TextBox事

2011-08-22 14:31:53

iPhone開發

2011-08-22 13:46:15

iPhone開發GameKit 藍牙
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 国产精品色 | 久久精品一级 | 国产馆 | 欧美8一10sex性hd | 国产一区二区精品在线观看 | 国产乱码精品1区2区3区 | 国产日韩欧美一区二区 | 亚洲成年在线 | 欧美一区二区在线观看视频 | 伊人久久在线观看 | 久久国产传媒 | 国产精品久久久久久久久久久久冷 | 午夜视频在线播放 | 99精品视频网| 日本激情视频中文字幕 | 国产精品久久精品 | 亚洲精品1区 | 亚洲成人激情在线观看 | 中国黄色在线视频 | 色999视频 | 国产精品一区二区在线 | 九九久久精品 | 色网站视频 | www.中文字幕.com | 男女视频在线免费观看 | 亚洲一区二区三区国产 | 日韩免费 | 亚洲精品久久久久久久久久久 | 9999视频| 欧美1—12sexvideos| 国产精品美女久久久久久久久久久 | 亚洲视频三区 | 国产精久久久久久 | 色爱综合网 | 国产综合欧美 | 国产传媒毛片精品视频第一次 | 亚洲免费在线视频 | 黄色电影在线免费观看 | 色999视频 | 国产东北一级毛片 | 欧美精品久久久 |