#import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h>
#import <UIKit/UIView.h>
#import <UIKit/UIStringDrawing.h>
#import <UIKit/UIKitDefines.h>
#import <UIKit/UIGestureRecognizer.h>
NS_ASSUME_NONNULL_BEGIN
@class UIImage, UIColor, UILabel, UIImageView, UIButton, UITextField, UITableView, UILongPressGestureRecognizer;
//tabview的分割線的樣式 tabview才能設(shè)置不屬于cell的屬性
typedef NS_ENUM(NSInteger, UITableViewCellSeparatorStyle) {
UITableViewCellSeparatorStyleNone,
UITableViewCellSeparatorStyleSingleLine,
UITableViewCellSeparatorStyleSingleLineEtched
} __TVOS_PROHIBITED;
typedef NS_ENUM(NSInteger, UITableViewCellFocusStyle) {
UITableViewCellFocusStyleDefault,
UITableViewCellFocusStyleCustom
} NS_ENUM_AVAILABLE_IOS(9_0);
#define UITableViewCellStateEditingMask UITableViewCellStateShowingEditControlMask
NS_CLASS_AVAILABLE_IOS(2_0) @interface UITableViewCell : UIView <NSCoding, UIGestureRecognizerDelegate>
//Cell的初始化方法驳遵,可以設(shè)置一個風格和標識符,風格的枚舉如下:
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(nullable NSString *)reuseIdentifier NS_AVAILABLE_IOS(3_0) NS_DESIGNATED_INITIALIZER;
typedef NS_ENUM(NSInteger, UITableViewCellStyle) {
UITableViewCellStyleDefault, // 默認風格,自帶標題和一個圖片視圖系吩,圖片在左
UITableViewCellStyleValue1, // 只有標題和副標題 副標題在右邊
UITableViewCellStyleValue2, // 只有標題和副標題,副標題在左邊標題的下邊
UITableViewCellStyleSubtitle // 自帶圖片視圖和主副標題科盛,主副標題都在左邊,副標題在下
};
//在storyBoard中取出時調(diào)用
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder NS_DESIGNATED_INITIALIZER;
//圖片視圖榨崩,風格允許時才會創(chuàng)建
@property (nonatomic, readonly, strong, nullable) UIImageView *imageView NS_AVAILABLE_IOS(3_0);
//標題標簽
@property (nonatomic, readonly, strong, nullable) UILabel *textLabel NS_AVAILABLE_IOS(3_0);
//副標題標簽
@property (nonatomic, readonly, strong, nullable) UILabel *detailTextLabel NS_AVAILABLE_IOS(3_0);
//如果需要添加簡單的View在cell上則需要添加在contentView上,
@property (nonatomic, readonly, strong) UIView *contentView;
//背景視圖
@property (nonatomic, strong, nullable) UIView *backgroundView;
//選中狀態(tài)下的背景視圖
@property (nonatomic, strong, nullable) UIView *selectedBackgroundView;
//多選選中時的背景視圖
@property (nonatomic, strong, nullable) UIView *multipleSelectionBackgroundView NS_AVAILABLE_IOS(5_0);
cell的標識符
@property (nonatomic, readonly, copy, nullable) NSString *reuseIdentifier;
//當被重用的cell將要顯示時,會調(diào)用這個方法恕出,這個方法最大的用武之地是當你自定義的cell上面有圖片時,如果產(chǎn)生了重用狈醉,圖片可能會錯亂(當圖片來自異步下載時及其明顯),這時我們可以重寫這個方法把內(nèi)容抹掉渣慕。
//必須調(diào)用super方法
- (void)prepareForReuse;
//cell被選中時的風格,枚舉如下:
@property (nonatomic) UITableViewCellSelectionStyle selectionStyle;
typedef NS_ENUM(NSInteger, UITableViewCellSelectionStyle) {
UITableViewCellSelectionStyleNone,//無
UITableViewCellSelectionStyleBlue,//藍色
UITableViewCellSelectionStyleGray,//灰色
UITableViewCellSelectionStyleDefault//默認 為藍色
};
//設(shè)置cell是否選中狀態(tài) 狀態(tài):默認不選中强经,沒有動畫
@property (nonatomic, getter=isSelected) BOOL selected;
//設(shè)置cell是否高亮狀態(tài)
@property (nonatomic, getter=isHighlighted) BOOL highlighted;
//與上面的兩個屬性對應
- (void)setSelected:(BOOL)selected animated:(BOOL)animated;
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated;
//獲取cell的編輯狀態(tài)信殊,枚舉如下
@property (nonatomic, readonly) UITableViewCellEditingStyle editingStyle;
typedef NS_ENUM(NSInteger, UITableViewCellEditingStyle) {
UITableViewCellEditingStyleNone,//無編輯
UITableViewCellEditingStyleDelete,//刪除編輯
UITableViewCellEditingStyleInsert//插入編輯
};
// 設(shè)置是否顯示cell自帶的自動排序控件
@property (nonatomic) BOOL showsReorderControl;
//注意:要讓cell實現(xiàn)拖動排序的功能玲躯,除了上面設(shè)置為YES汞窗,還需實現(xiàn)代理中的如下方法:
/*-(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath{
return YES;
}
-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{
}*/
//設(shè)置編輯狀態(tài)下是否顯示縮進
@property (nonatomic) BOOL shouldIndentWhileEditing;
//設(shè)置附件視圖的風格(cell最右側(cè)顯示的視圖) 枚舉如下:
@property (nonatomic) UITableViewCellAccessoryType accessoryType;
typedef NS_ENUM(NSInteger, UITableViewCellAccessoryType) {
UITableViewCellAccessoryNone, // 沒有視圖
UITableViewCellAccessoryDisclosureIndicator, // cell右側(cè)顯示一個灰色箭頭
UITableViewCellAccessoryDetailDisclosureButton, // 顯示詳情符號和灰色箭頭
UITableViewCellAccessoryCheckmark, // cell右側(cè)顯示藍色對號
UITableViewCellAccessoryDetailButton // cell右側(cè)顯示一個詳情符號
};
//附件視圖
@property (nonatomic, strong, nullable) UIView *accessoryView;
//cell編輯時的附件視圖風格
@property (nonatomic) UITableViewCellAccessoryType editingAccessoryType;
//cell編輯時的附件視圖
@property (nonatomic, strong, nullable) UIView *editingAccessoryView;
//設(shè)置內(nèi)容區(qū)域的縮進級別,默認為0
@property (nonatomic) NSInteger indentationLevel;
//設(shè)置每個級別的縮進寬度 默認為10.0
@property (nonatomic) CGFloat indentationWidth;
//設(shè)置分割線的偏移量
@property (nonatomic) UIEdgeInsets separatorInset NS_AVAILABLE_IOS(7_0) UI_APPEARANCE_SELECTOR __TVOS_PROHIBITED;
//設(shè)置是否編輯狀態(tài)
@property (nonatomic, getter=isEditing) BOOL editing;
- (void)setEditing:(BOOL)editing animated:(BOOL)animated;
//返回是否目前正在顯示刪除按鈕
@property(nonatomic, readonly) BOOL showingDeleteConfirmation;
//設(shè)置焦點類型
@property (nonatomic) UITableViewCellFocusStyle focusStyle NS_AVAILABLE_IOS(9_0) UI_APPEARANCE_SELECTOR;
typedef NS_ENUM(NSInteger, UITableViewCellFocusStyle) {
UITableViewCellFocusStyleDefault,//當它變得集中時誓斥,單元格將以標準的系統(tǒng)定義的方式改變其外觀毕谴。這是默認的焦點樣式。
UITableViewCellFocusStyleCustom//當它聚焦時舀武,單元格不會自動改變其外觀。指定此樣式可以為單元格創(chuàng)建自己的自定義外觀寻馏。
//建議您通過子類化UITableViewCell并覆蓋didUpdateFocusInContext:withAnimationCoordinator:來創(chuàng)建自定義的單元格。
} NS_ENUM
//cell狀態(tài)將要轉(zhuǎn)換時調(diào)用的函數(shù)家乘,可以在子類中重寫
- (void)willTransitionToState:(UITableViewCellStateMask)state NS_AVAILABLE_IOS(3_0);
//cell狀態(tài)已經(jīng)轉(zhuǎn)換時調(diào)用的函數(shù)耀找,可以在子類中重寫双炕,狀態(tài)枚舉如下:
- (void)didTransitionToState:(UITableViewCellStateMask)state NS_AVAILABLE_IOS(3_0);
typedef NS_OPTIONS(NSUInteger, UITableViewCellStateMask) {
UITableViewCellStateDefaultMask = 0,//默認狀態(tài)
UITableViewCellStateShowingEditControlMask = 1 << 0,//編輯狀態(tài)
UITableViewCellStateShowingDeleteConfirmationMask = 1 << 1//確認刪除狀態(tài)
};
@end
@interface UITableViewCell (UIDeprecated)
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(nullable NSString *)reuseIdentifier NS_DEPRECATED_IOS(2_0, 3_0) __TVOS_PROHIBITED;
//注意:下面這些方法已經(jīng)全部在IOS3.0后被廢棄了丹拯,雖然還有效果融求,但是會被警告
//設(shè)置標題
@property (nonatomic, copy, nullable) NSString *text NS_DEPRECATED_IOS(2_0, 3_0) __TVOS_PROHIBITED;
//設(shè)置字體
@property (nonatomic, strong, nullable) UIFont *font NS_DEPRECATED_IOS(2_0, 3_0) __TVOS_PROHIBITED;
//設(shè)置對其模式
@property (nonatomic) NSTextAlignment textAlignment NS_DEPRECATED_IOS(2_0, 3_0) __TVOS_PROHIBITED;
//設(shè)置斷行模式
@property (nonatomic) NSLineBreakMode lineBreakMode NS_DEPRECATED_IOS(2_0, 3_0) __TVOS_PROHIBITED;
//設(shè)置字體顏色
@property (nonatomic, strong, nullable) UIColor *textColor NS_DEPRECATED_IOS(2_0, 3_0) __TVOS_PROHIBITED;
//設(shè)置選中狀態(tài)下的字體顏色
@property (nonatomic, strong, nullable) UIColor *selectedTextColor NS_DEPRECATED_IOS(2_0, 3_0) __TVOS_PROHIBITED;
//設(shè)置圖片
@property (nonatomic, strong, nullable) UIImage *image NS_DEPRECATED_IOS(2_0, 3_0) __TVOS_PROHIBITED;
//設(shè)置選中狀態(tài)時的圖片
@property (nonatomic, strong, nullable) UIImage *selectedImage NS_DEPRECATED_IOS(2_0, 3_0) __TVOS_PROHIBITED;
// 設(shè)置編輯的時候是否隱藏附件視圖七芭,默認為yes
@property (nonatomic) BOOL hidesAccessoryWhenEditing NS_DEPRECATED_IOS(2_0, 3_0) __TVOS_PROHIBITED;
// 使用-tableView:commitEditingStyle:forRowAtIndexPath:或者-tableView:accessoryButtonTappedForRowWithIndexPath: instead
@property (nonatomic, assign, nullable) id target NS_DEPRECATED_IOS(2_0, 3_0) __TVOS_PROHIBITED;
@property (nonatomic, nullable) SEL editAction NS_DEPRECATED_IOS(2_0, 3_0) __TVOS_PROHIBITED;
@property (nonatomic, nullable) SEL accessoryAction NS_DEPRECATED_IOS(2_0, 3_0) __TVOS_PROHIBITED;
@end
NS_ASSUME_NONNULL_END
API--UITableViewCell API詳解
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進店門妄壶,熙熙樓的掌柜王于貴愁眉苦臉地迎上來例嘱,“玉大人奢浑,你說我怎么就攤上這事壤蚜≥撼螅” “怎么了萧豆?”我有些...
- 文/不壞的土叔 我叫張陵,是天一觀的道長卿嘲。 經(jīng)常有香客問我盒让,道長姨蝴,這世上最難降的妖魔是什么同木? 我笑而不...
- 正文 為了忘掉前任洲尊,我火速辦了婚禮惊来,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘厘擂。我一直安慰自己避凝,他們只是感情好,可當我...
- 文/花漫 我一把揭開白布含潘。 她就那樣靜靜地躺著盆均,像睡著了一般饰抒。 火紅的嫁衣襯著肌膚如雪蔗草。 梳的紋絲不亂的頭發(fā)上,一...
- 文/蒼蘭香墨 我猛地睜開眼僚碎,長吁一口氣:“原來是場噩夢啊……” “哼矛双!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起,我...
- 正文 年R本政府宣布,位于F島的核電站炕檩,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜舆吮,卻給世界環(huán)境...
- 文/蒙蒙 一锋恬、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧晕窑,春花似錦、人聲如沸疾牲。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽角虫。三九已至,卻和暖如春妇穴,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背曲梗。 一陣腳步聲響...
推薦閱讀更多精彩內(nèi)容
- - (CGFloat)tableView:(UITableView *)tableView estimatedHe...
- cat API 各命令詳解 cat aliases 也可以查詢指定的別名 cat allocation alloc...
- 最近在UItableViewCell的緩沖機制胳岂,相信很多開發(fā)者都已經(jīng)清楚,假設(shè)手機屏幕一屏有6個cell产园,當再向上...
- 在這世界上,有的父母以身作則恰画,教給了孩子一切優(yōu)秀的品質(zhì)跨晴,并給了他們最好的教育環(huán)境,卻只期望孩子能夠一生無憂焕妙,平安喜...
- 1. 簡單工廠模式 如何理解簡單工廠,工廠方法湖员, 抽象工廠三種設(shè)計模式唤反? 簡單工廠的生活場景逆趋,賣早點的小攤販,他給...