您的位置:首页 > 产品设计 > UI/UE

UITableView Class 参考 (1)<Creating Table View Cells>

2014-01-13 16:47 911 查看
Creating Table View Cells

– registerNib:forCellReuseIdentifier:
– registerClass:forCellReuseIdentifier:
– dequeueReusableCellWithIdentifier:forIndexPath:
– dequeueReusableCellWithIdentifier:

registerNib:forCellReuseIdentifier:

Registers a nib object containing a cell with the table view under a specified identifier.
- (void)registerNib:(UINib *)nib
forCellReuseIdentifier:(NSString *)identifier
Parameters
nib
A nib object that specifies the nib file to use to create the cell. This parameter cannot be
nil.
identifier
The reuse identifier for the cell. This parameter must not be
nil and must not be an empty string.
Discussion
Prior to dequeueing any cells, call this method or the
registerClass:forCellReuseIdentifier: method to tell the table view how to create new cells. If a cell of the specified type is not currently in a reuse queue, the table view uses the provided information to create a new cell object automatically.
If you previously registered a class or nib file with the same reuse identifier, the nib you specify in the nib parameter replaces the old entry. You may specify
nil for nib if you want to unregister the nib from the specified reuse identifier.
详细说明:
在出列任何cell之前,调用这个方法或者registerClass:forCellReuseIdentifier: 方法让tableview去创建新的cells。如果指定类型的cell不在当前可用的队列中,tableview使用提供的信息去自动创建新的cell对象。
如果你之前使用了相同的复用标示符去注册一个类或者nib文件,你在nib参数中指定的nib代替了旧的entry。如果你想从指定的可复用指示器中解除注册nib,你可以把nib设为nil.

dequeueReusableCellWithIdentifier:

Returns a reusable table-view cell object located by its identifier.
- (id)dequeueReusableCellWithIdentifier:(NSString
*)identifier
Parameters
identifier
A string identifying the cell object to be reused. This parameter must not be
nil.
Return Value
A
UITableViewCell object with the associated identifier or
nil if no such object exists in the reusable-cell queue.
Discussion
For performance reasons, a table view'€™s data source should generally reuse

UITableViewCell objects when it assigns cells to rows in its

tableView:cellForRowAtIndexPath: method. A table view maintains a queue or list of

UITableViewCell objects that the data source has marked for reuse. Call this method from your data source object when asked to provide a new cell for the table view. This method dequeues an existing cell if one is available or creates
a new one using the class or nib file you previously registered. If no cell is available for reuse and you did not register a class or nib file, this method returns
nil.
If you registered a class for the specified identifier and a new cell must be created, this method initializes the cell by calling its

initWithStyle:reuseIdentifier: method. For nib-based cells, this method loads the cell object from the provided nib file. If an existing cell was available for reuse, this method calls the cell’s

prepareForReuse method instead.
详细说明:
由于性能原因,在tableview 的tableView:cellForRowAtIndexPath:方法中,当它为每一行指定cell时,它的数据源应该复用UITableViewCell对象。table view保存了包含UITableViewCell对象的队列或者列表,这些UITableViewCell是数据源标记为复用的对象。当要求为table view提供新的cell时,从你的数据源对象中调用这个方法。如果已经存在一个可用的cell,那么这个方法会出列这个cell。如果不存在可用的cell,那么用你先前注册的类或者nib文件创建一个新的cell。如果没有可复用的cell并且你没有注册一个类或者
nib文件,那么这个方法返回nil。
如果你为指定的identifier注册一个类,并且一个新的cell必须被创建,这个方法通过调用 initWithStyle:reuseIdentifier:方法初始化cell。对于基于nib的cell,这个方法从提供的nib文件中加载cell对象,如果一个已经存在的cell可以复用,那么这个方法调用这个cell的prepareForReuse方法。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  iOS uitableview