IOS中UITableViewCell使用詳解

2021-07-10 17:20:36 字數 4877 閱讀 5849

cell的初始化方法,可以設定乙個風格和識別符號,風格的列舉如下:?

1

2

3

4

5

6

typedefns_enum(nsinteger, uitableviewcellstyle) ;

@property(nonatomic, readonly, retain) 

uiimageview

*imageview;

檢視,風格允許時才會建立

@property(nonatomic, readonly, retain) 

uilabel

*textlabel;

標題標籤

@property(nonatomic, readonly, retain) 

uilabel

*detailtextlabel;

副標題標籤

@property(nonatomic, readonly, retain) 

uiview

*contentview;

容納檢視,任何cell的子檢視都應該新增在這個上面

@property (nonatomic, retain) uiview                *backgroundview;

背景檢視

@property (nonatomic, retain) uiview                *selectedbackgroundview;

選中狀態下的背景檢視

@property (nonatomic, retain) uiview              *multipleselectionbackgroundview;

多選選中時的背景檢視

@property (nonatomic, readonly, copy) nsstring      *reuseidentifier;

cell的識別符號

- (void)prepareforreuse; 

@property

(nonatomic

) uitableviewcellselectionstyleselectionstyle;  

cell被選中時的風格,列舉如下:?

1

2

3

4

5

6

typedefns_enum(nsinteger, uitableviewcellselectionstyle) ;

@property (nonatomic, getter=isselected) bool         selected;  

設定cell是否選中狀態

@property (nonatomic, getter=ishighlighted) bool      highlighted;   

設定cell是否高亮狀態

- (void)setselected:(bool)selected animated:(bool)animated;  

- (void)sethighlighted:(bool)highlighted animated:(bool)animated; 

與上面的兩個屬性對應

@property

(nonatomic

, readonly

) uitableviewcelleditingstyleeditingstyle; 

獲取cell的編輯狀態,列舉如下?

1

2

3

4

5

typedefns_enum(nsinteger, uitableviewcelleditingstyle) ;

@property (nonatomic) bool                            showsreordercontrol; 

設定是否顯示cell自帶的自動排序控制項

注意:要讓cell實現拖動排序的功能,除了上面設定為yes,還需實現**中的如下方法:

-(bool)tableview:(uitableview *)tableview canmoverowatindexpath:(nsindexpath *)indexpath

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

@property (nonatomic) bool                            shouldindentwhileediting;

設定編輯狀態下是否顯示縮排

@property

(nonatomic

) uitableviewcellaccessorytypeaccessorytype; 

設定附件檢視的風格(cell最右側顯示的檢視)

列舉如下: ?

12

3

4

5

6

7

typedefns_enum(nsinteger, uitableviewcellaccessorytype) ;

@property (nonatomic, retain) uiview                 *accessoryview;  

附件檢視

@property (nonatomic) uitableviewcellaccessorytype    editingaccessorytype; 

cell編輯時的附件檢視風格

@property (nonatomic, retain) uiview                 *editingaccessoryview;  

cell編輯時的附件檢視

@property (nonatomic) nsinteger                       indentationlevel; 

設定內容區域的縮排級別

@property (nonatomic) cgfloat                         indentationwidth; 

設定每個級別的縮排寬度

@property (nonatomic) uiedgeinsets                    separatorinset;

設定分割線的偏移量

@property (nonatomic, getter=isediting) bool          editing; 

- (void)setediting:(bool)editing animated:(bool)animated;

設定是否編輯狀態

@property(nonatomic, readonly) bool                   showingdeleteconfirmation;

返回是否目前正在顯示刪除按鈕

- (void)willtransitiontostate:(uitableviewcellstatemask)state;

cell狀態將要轉換時呼叫的函式,可以在子類中重寫

- (void)didtransitiontostate:(uitableviewcellstatemask)state;

cell狀態已經轉換時呼叫的函式,可以在子類中重寫,狀態列舉如下: ?

12

3

4

5

typedefns_options(nsuinteger, uitableviewcellstatemask) ;

注意:下面這些方法已經全部在ios3.0後被廢棄了,雖然還有效果,但是會被警告

@property(nonatomic, copy)   

nsstring

*text;

設定標題

@property(nonatomic, retain) 

uifont

*font;

設定字型

@property (nonatomic) nstextalignment   textalignment;

設定對其模式

@property (nonatomic) nslinebreakmode   linebreakmode;

設定斷行模式

@property(nonatomic, retain) 

uicolor

*textcolor;

設定字型顏色

@property (nonatomic, retain) uicolor  *selectedtextcolor;

設定選中狀態下的字型顏色

@property(nonatomic, retain) 

uiimage

*image; 設定

@property(nonatomic, retain) 

uiimage

*selectedimage;

設定選中狀態時的

@property (nonatomic) bool              hidesaccessorywhenediting;

設定編輯的時候是否隱藏附件檢視

iOS7中UITableView中cell的使用

今天看到很多人提到,在ios7中,使用uitableview的時候,對於cell要注意 cell addsubview usertextfield 這種用法不能再用了,應該使用 cell.contentview addsubview usertextfield 的方式。如某人就遇到這種問題 調查了一...

iOS7中UITableView中cell的使用

分類 ios oc 2013 09 26 15 01 3099人閱讀收藏 舉報 今天看到很多人提到,在ios7中,使用uitableview的時候,對於cell要注意 cell addsubview usertextfield 這種用法不能再用了,應該使用 cell.contentview adds...

iOS中uitableview滑動刪除新增按鈕

一 如果我們不新增任何按鈕,直接需要乙個刪除的話,很簡單 void tableview uitableview tableview commiteditingstyle uitableviewcelleditingstyle editingstyle forrowatindexpath nsinde...