IOS UI基礎07,iosui07

來源:互聯網
上載者:User

IOS UI基礎07,iosui07

  • TableView

    • 屬性

         // 設定每一行cell的高度   @property (nonatomic)CGFloat rowHeight;   // 設定每一組頭部的高度   @property (nonatomic)CGFloat sectionHeaderHeight;   // 設定分割線顏色   @property (nonatomic, retain) UIColor *separatorColor   // 設定表頭控制項   @property (nonatomic, retain) UIView *tableHeaderView;   // 設定表尾控制項   @property (nonatomic, retain) UIView *tableFooterView;   // 2.組頭組尾的高   self.tableView.sectionHeaderHeight = 55;   self.tableView.sectionFooterHeight = 22;   // 3.設定整個tablView的頭部/尾部視圖   self.tableView.tableHeaderView = [[UISwitch alloc] init];   self.tableView.tableFooterView = [UIButton buttonWithType:UIButtonTypeInfoDark];   // 4.設定我們分割線顏色(clearColor相當於取消系統分割線)   //self.tableView.separatorColor = [UIColor clearColor];  // 5.設定分割線樣式   self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    • 資料來源方法
        //cell有多少組-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView //告訴tableView第section組有多少行-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section//告訴tableView每一行顯示什麼內容(tableView的每一行都是UITableViewCell)-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath //告訴tableView第section組的頭部標題文字-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section // 告訴tableView第section組的尾部標題文字-(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section//返回每一組的索引標題- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView // 返回每個cell的高度 -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath//刪除資料- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;//
    • 代理方法
       // 只要實現了這個方法,左滑出現按鈕的功能就有了(一旦左滑出現了N個按鈕,tableView就進入了編輯模式, tableView.editing = YES)         -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath     //左滑cell時出現什麼按鈕       -(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath    {      UITableViewRowAction *action0 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"關注" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {        NSLog(@"點擊了關注");        // 收回左滑出現的按鈕(退出編輯模式)        tableView.editing = NO;    }];    UITableViewRowAction *action1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"刪除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {        [self.wineArray removeObjectAtIndex:indexPath.row];        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];    }];    return @[action1, action0];}    //代理方法擷取點滴選中行,行號    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;    //允許編輯選中行    - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath;
  • UITableViewCell

    • 屬性:
      //設定cell右邊的指示樣式//accessoryView的優先順序 > accessoryType//cell.accessoryView = [[UISwitch alloc] init];@property (nonatomic) UITableViewCellAccessoryType    accessoryType;// default is UITableViewCellAccessoryNone. use to set standard type
    • Cell 建立

      • 註冊建立

        [self.tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:ID];//註冊後可以直接從緩衝中找建立好的UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
      • 非註冊建立

        • 先從緩衝持中尋找

           UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:ID];
        • 查不到在建立

           if (nil==cell) {cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID]; }

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.