自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

iPhone開(kāi)發(fā) UITableView代碼實(shí)現(xiàn)實(shí)例

移動(dòng)開(kāi)發(fā) iOS
本文介紹的iPhone開(kāi)發(fā) UITableView代碼實(shí)現(xiàn)實(shí)例,主要介紹了UITableView的使用方法,我們先來(lái)看內(nèi)容。

iPhone開(kāi)發(fā) UITableView代碼實(shí)現(xiàn)實(shí)例是本文要介紹的內(nèi)容,介紹了UITableView的基本操作,以小實(shí)例實(shí)現(xiàn),我們來(lái)看內(nèi)容。
 
1、前題條件

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

1.2 UITableView需要繼續(xù)兩個(gè)協(xié)議<UITableViewDelegate,UITableViewDataSource>

兩個(gè)協(xié)議的方法為:

--行的數(shù)量:

  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.   //默認(rèn)樣式  
  17.   cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault  
  18.                                    reuseIdentifier: SimpleTableIdentifier] autorelease];  
  19.  }  
  20.  //文字的設(shè)置  
  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. //自定識(shí)別頭及高度  
  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、取消點(diǎn)擊動(dòng)畫

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

5、滾動(dòng)路徑標(biāo)識(shí),直至指數(shù)連續(xù)接收器在屏幕上的特定位置

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

indexPath

索引路徑標(biāo)識(shí)在其行的索引,其部分指標(biāo)表視圖行。

scrollPosition

 一個(gè)常數(shù),在接收標(biāo)識(shí)表查看行(上,中,下)的相對(duì)位置滾動(dòng)時(shí)結(jié)束。

animated

是如果你要?jiǎng)赢嬙谖恢酶淖?,沒(méi)有是否應(yīng)立即生效。

實(shí)例代碼:

  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];//動(dòng)畫開(kāi)始     
  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開(kāi)發(fā) UITableView代碼實(shí)現(xiàn)實(shí)例

代碼如下:

  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將要顯示時(shí)事件

  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;  

小結(jié):iPhone開(kāi)發(fā) UITableView代碼實(shí)現(xiàn)實(shí)例的內(nèi)容介紹完了,希望本文對(duì)你有所幫助!

責(zé)任編輯:zhaolei 來(lái)源: 互聯(lián)網(wǎng)
相關(guān)推薦

2011-07-28 10:11:54

iPhone開(kāi)發(fā) 備忘

2011-08-08 10:42:46

iPhone UITableVie 分頁(yè)

2011-07-27 11:14:37

iPhone UITableVie

2011-08-15 13:44:07

iPhone開(kāi)發(fā)UITableView

2011-07-25 18:02:51

iPhone LibFetion 移植

2011-08-08 16:56:44

iPhone 字符處理 視圖

2011-08-19 10:01:09

iPhone應(yīng)用SqliteUITableView

2011-08-02 17:14:41

iPhone應(yīng)用 UITableVie

2011-07-25 14:44:41

iPhone iPhone開(kāi)發(fā) 截屏

2011-07-22 17:24:46

iPhone 視圖

2011-08-15 11:23:41

iPhone開(kāi)發(fā)循環(huán)滾動(dòng)UIScrollVie

2011-08-01 13:13:19

iPhone開(kāi)發(fā) 圖片

2009-07-22 11:27:36

iBATIS模糊查詢

2009-09-01 16:59:25

C#畫直線

2009-08-27 18:09:49

C#接口的實(shí)現(xiàn)

2009-09-01 13:59:01

C#操作Excel

2009-08-17 14:41:47

C#進(jìn)度條實(shí)現(xiàn)

2009-09-09 12:55:59

C# TextBox事

2011-08-22 14:31:53

iPhone開(kāi)發(fā)

2011-08-22 13:46:15

iPhone開(kāi)發(fā)GameKit 藍(lán)牙
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)