开发者

Can I provide nil for the -dequeueReusableCellWithIdentifier: method?

开发者 https://www.devze.com 2022-12-26 02:34 出处:网络
dequeueReusableCellWithIdentifier: Returns a reusable table-view cell object located by its identifier.

dequeueReusableCellWithIdentifier: Returns a reusable table-view cell object located by its identifier.

  • (UITableViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifier

Parameters identifier A string identifying the cell object to be reused. By default, a reusable cell's identifier is its class name, but you can change it to any arbitrary value.

Ok so if by default it's the class name, why should I put much brain force into thinking about an identifier? Could I provide just nil? Would it then use the class name? Or what did they try to say here? Must I make an NSString with 开发者_JAVA百科the class name by myself and provide it as identifier?


No. The identifier will be used as a key in an internal NSMutableDictionary of NSArray to store the reusable cells. If you provide nil, the -objectForKey: used in -dequeueReusableCellWithIdentifier: will crash.

Besides, a table may have cells from different (sub)classes of UITableViewCell, so there's no good default value to pass either.

0

精彩评论

暂无评论...
验证码 换一张
取 消