UITableView 高階應用

2021-07-22 21:10:52 字數 4169 閱讀 4632

uitableview 提供了編輯方法:重新整理,刪除,插入等等

一、下拉重新整理

二、刪除

注意左上角按鈕標題的改變

三、插入

跳到下乙個頁面

實現**:

viewcontroller.m

#import "viewcontroller.h"

#import "customtableviewcontroller.h"

@inte***ce viewcontroller ()@property (nonatomic,strong) uitableview *tableview;

@property (nonatomic,strong) nsmutablearray *datasource;

//重新整理控制項

@property (nonatomic,strong) uirefreshcontrol *refreshcontrol;

@end

@implementation viewcontroller

- (instancetype)initwithcoder:(nscoder *)coder

return self;

}- (void)viewdidload

#pragma mark - beginrefresh

- (void)beginrefresh:(uirefreshcontrol *)sender

#pragma mark - addnewfont

//插入新字型

- (void)addnewfont];

[alertcontroller addaction:cancelaction];

[alertcontroller addaction:sureaction];

[self presentviewcontroller:alertcontroller animated:yes completion:nil];

}#pragma mark - nextaction

- (void)nextaction:(uibarbuttonitem *)sender

- (void)editaction:(uibarbuttonitem *)sender

#pragma mark - 刪除

//1.配置刪除按鈕的title

- (nsstring *)tableview:(uitableview *)tableview titlefordeleteconfirmationbuttonforrowatindexpath:(nsindexpath *)indexpath

//2.提交刪除狀態

- (void)tableview:(uitableview *)tableview commiteditingstyle:(uitableviewcelleditingstyle)editingstyle forrowatindexpath:(nsindexpath *)indexpath

}#pragma mark - 移動

//移動cell

- (void)tableview:(uitableview *)tableview moverowatindexpath:(nsindexpath *)sourceindexpath toindexpath:(nsindexpath *)destinationindexpath

#pragma mark - - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath

@end

customtableviewcontroller.m

#import "customtableviewcontroller.h"

#import "customtableviewcell.h"

@inte***ce customtableviewcontroller ()

//資料來源

@property (nonatomic,strong)nsmutablearray *datasource;

@end

@implementation customtableviewcontroller

- (void)viewdidload

- (void)loaddatasource;

[_datasource addobject:dic];

}//重新整理**

[self.tableview reloaddata];

}#pragma mark - table view data source

- (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath

//獲取到每一行的資料字典

nsdictionary *dic = _datasource[indexpath.row];

cell.logoimageview.image = [uiimage imagenamed:dic[@"image"]];

cell.titleinfolabel.text = dic[@"title"];

return cell;

}//表頭高度

- (cgfloat)tableview:(uitableview *)tableview heightforheaderinsection:(nsinteger)section

//自定義表頭

- (uiview *)tableview:(uitableview *)tableview viewforheaderinsection:(nsinteger)section

//指定每一行 cell 的高度

- (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath

@end

customtableviewcell.h

#import @inte***ce customtableviewcell : uitableviewcell

//@property (nonatomic,strong) uiimageview *logoimageview;

//標籤

@property (nonatomic,strong) uilabel *titleinfolabel;

@end

customtableviewcell.m

#import "customtableviewcell.h"

@implementation customtableviewcell

- (instancetype)initwithstyle:(uitableviewcellstyle)style reuseidentifier:(nsstring *)reuseidentifier

return self;

}- (void)setupui

@end

新增和文字,在cell中定義uiimageview和uilabel.需要重寫cell.

UITableView的分割線的應用

使用cell的分割線頂滿格 self.tableview setseparatorinset uiedgeinsetszero self.tableview setlayoutmargins uiedgeinsetszero 在cell的方法裡面設定這句話 cell setseparatorinse...

Apache MINA 應用高階

li.zhongnan hotmail.com 1。mina 框架簡介 下圖為本人根據對mina的簡要理解,所畫出來的框架簡圖 session可以理解為伺服器與客戶端的特定連線,該連線由伺服器位址 埠以及客戶端位址 埠來決定。客戶端發起請求時,指定伺服器位址和埠,客戶端也會指定或者根據網路路由資訊自...

vi高階應用

linux 2008 10 29 23 33 53 閱讀39 字型大小 大 中小訂閱 find name doc exec rm 2,用find grep,xargs 的組合 find grep doc xargs i rm 看上去,第乙個簡單一些,但很類似,不過如果要實現 刪除那些沒有指定字尾的檔...