IOS學習筆記(三)TableVIew

來源:互聯網
上載者:User

標籤:

如果有需要跟蹤NSArray中的內容,需要重寫descriptionWithLocal 方法。首先建立一個NSArray 的Category,在建立出來的.m檔案中加入下列代碼

 

- (NSString *)descriptionWithLocal:(id)local 

{

  NSMutableString *string = [NSMutableString string];

  [string appendString:@"("];

  for (id obj in self) {

    [string appendFormat:@"\n\t\"%@\",", obj];

  }

  [string appendString:@"\n)"];

  return string;

}

如此一來,用NSLog顯示NSArry中的資料不再是utf-8編碼,顯示為原來資料。

 

UITableView

需要一個資料來源來顯示資料


1.需加入資料來源協議                                UITableViewDataSource     ;     <

2. 設定表格的組數                              - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView   ;      <      

3.設定每個分組中的行數                       - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section  ;    <

4.設定每個分組中顯示的資料內容               - (UITableViewCell *)tableView:(UITableView *)tableViewcellForRowAtIndexPaht:(NSIndexPath *)indexPath  {

                    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIndentifier:nil];

                    indexPath.section      即為分組名

}  cell即是返回的分組中的資料。                   

5.設定分組的標題            - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSIntger)secton       ;    <

6.設定頁尾的標題, 分組底部的子標題        - (NSString *)tableView:(UITableVIew *)tableView titleForFooterInSection:(NSInteger)section     ;    <

7.字典返回所有keys的方法         NSArray *items = [self.cities allKeys];    <   裡面資料出來的順序是亂的

8.將UITableView中的分組分開(即設定style,但style只能在初始化的時候設定)  

                    UITableView *tableView = [[UITableView alloc] initWithFrame: style:(UITableViewStyle)]         ;     <

9.代理方法:                     - (void)tableView:(UITableView *)tableViewdidSelectRowAtIndexPath:(NSIndex *)indexPaht   ;   <

 

 

細節決定成敗!                     

IOS學習筆記(三)TableVIew

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.