[课堂实践与项目]系统UITableViewCell的内嵌属性的说明和部分属性使用

本文详细介绍了UITableViewCell的基本属性及其使用方法,包括初始化、图片显示、文本标签配置、自定义视图添加、背景样式设置等核心内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.今天学习了UITableViewCell的有关属性。没有牵扯自定义的Cell。我们就先来看看UITableViewCell的有关属性和使用方法。

1.- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 

 NSString *cellIndentifiter = @"CellIndentifiter";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentifiter];


2.如图

@property (nonatomic, readonly, retain) UIImageView *imageView

3.如图

@property (nonatomic, readonly, retain) UILabel     *textLabel NS_AVAILABLE_IOS(3_0); 

4.如图

@property (nonatomic, readonly, retain) UILabel     *detailTextLabel

    NSString *textfont =[self.array objectAtIndex:row];
    cell.textLabel.font = [UIFont fontWithName:textfont size:20];
    cell.textLabel.text = textfont;
    cell.detailTextLabel.text = @"detailText";
    cell.imageView.image = [UIImage imageNamed:@"1.png"];


//------------

5.

// If you want to customize cells by simply adding additional views, you should add them to the content view so they will be positioned appropriately as the cell transitions into and out of editing mode.

@property (nonatomic, readonly, retain) UIView      *contentView;

6.

// Default is nil for cells in UITableViewStylePlain, and non-nil for UITableViewStyleGrouped. The 'backgroundView' will be added as a subview behind all other views.

@property (nonatomic, retain) UIView                *backgroundView;

7.

@property (nonatomic, retain) UIView                *selectedBackgroundView;

8.

// If not nil, takes the place of the selectedBackgroundView when using multiple selection.

@property (nonatomic, retain) UIView                *multipleSelectionBackgroundView NS_AVAILABLE_IOS(5_0);

9.

@property (nonatomic, readonly, copy) NSString      *reuseIdentifier;

- (void)prepareForReuse;                                                        // if the cell is reusable (has a reuse identifier), this is called just before the cell is returned from the table view method dequeueReusableCellWithIdentifier:.  If you override, you MUST call super.

10.

@property (nonatomic) UITableViewCellSelectionStyle   selectionStyle;    

11.

@property (nonatomic, getter=isSelected) BOOL         selected;   

12.

@property (nonatomic, getter=isHighlighted) BOOL      highlighted; 

13。

- (void)setSelected:(BOOL)selected animated:(BOOL)animated;    

14.

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated;   

15.

@property (nonatomic, readonly) UITableViewCellEditingStyle editingStyle;         // default is UITableViewCellEditingStyleNone. This is set by UITableView using the delegate's value for cells who customize their appearance accordingly.

@property (nonatomic) BOOL                            showsReorderControl;        // default is NO

@property (nonatomic) BOOL                            shouldIndentWhileEditing;   // default is YES.  This is unrelated to the indentation level below.

16.

@property (nonatomic) UITableViewCellAccessoryType    accessoryType;              // default is UITableViewCellAccessoryNone. use to set standard type

typedef NS_ENUM(NSInteger, UITableViewCellAccessoryType) {

    UITableViewCellAccessoryNone,                   // don't show any accessory view

    UITableViewCellAccessoryDisclosureIndicator,    // regular chevron. doesn't track

    UITableViewCellAccessoryDetailDisclosureButton, // info button w/ chevron. tracks

    UITableViewCellAccessoryCheckmark,              // checkmark. doesn't track

    UITableViewCellAccessoryDetailButton NS_ENUM_AVAILABLE_IOS(7_0) // info button. tracks

};







//-----------------

17.

@property (nonatomic, retain) UIView                 *accessoryView;              // if set, use custom view. ignore accessoryType. tracks if enabled can calls accessory action

//accessoryView 是可以设置的,但是 xy的位置是固定不可变的。和accessoryType 所处的位置相同,但是如果改变view的宽高,还是可以改变的



18.

@property (nonatomic) UITableViewCellAccessoryType    editingAccessoryType;       // default is UITableViewCellAccessoryNone. use to set standard type

@property (nonatomic, retain) UIView                 *editingAccessoryView;       // if set, use custom view. ignore editingAccessoryType. tracks if enabled can calls accessory action

19

@property (nonatomic) NSInteger                       indentationLevel;           // adjust content indent. default is 0

@property (nonatomic) CGFloat                         indentationWidth;           // width for each level. default is 10.0

@property (nonatomic) UIEdgeInsets                    separatorInset NS_AVAILABLE_IOS(7_0) UI_APPEARANCE_SELECTOR; // allows customization of the separator frame

20

@property(nonatomic, getter=isEditing) BOOL           editing;                    // show appropriate edit controls (+/- & reorder). By default -setEditing: calls setEditing:animated: with NO for animated.

- (void)setEditing:(BOOL)editing animated:(BOOL)animated;

21

@property(nonatomic, readonly) BOOL                   showingDeleteConfirmation;  // currently showing "Delete" button


22

// These methods can be used by subclasses to animate additional changes to the cell when the cell is changing state

// Note that when the cell is swiped, the cell will be transitioned into the UITableViewCellStateShowingDeleteConfirmationMask state,

// but the UITableViewCellStateShowingEditControlMask will not be set.

- (void)willTransitionToState:(UITableViewCellStateMask)state NS_AVAILABLE_IOS(3_0);

- (void)didTransitionToState:(UITableViewCellStateMask)state NS_AVAILABLE_IOS(3_0);

typedef NS_OPTIONS(NSUInteger, UITableViewCellStateMask) {

    UITableViewCellStateDefaultMask                     = 0,

    UITableViewCellStateShowingEditControlMask          = 1 << 0,

    UITableViewCellStateShowingDeleteConfirmationMask   = 1 << 1

};



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值