美文网首页
认识 - registerClass:forCellReuseI

认识 - registerClass:forCellReuseI

作者: 梅西和他的世界杯 | 来源:发表于2016-01-17 15:41 被阅读3183次

    标签: iOS,苹果开发文档


    - registerClass:forCellReuseIdentifier:

    Registers a class for use in creating new table cells.

    Declaration

    SWIFT
         func registerClass(_ cellClass: AnyClass?,
    forCellReuseIdentifier identifier: String)
    OBJECTIVE-C
    - (void)registerClass:(Class _Nullable)cellClass
    forCellReuseIdentifier:(NSString * _Nonnull)identifier
    

    Parameters

    cellClass
    The class of a cell that you want to use in the table.

    identifier
    The reuse identifier for the cell. This parameter must not be nil and must not be an empty string.
    重用标识,参数一定不能为nil,一定不能为空字符串。

    Discussion

    Prior to dequeueing any cells, call this method or the registerNib: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.

    出队列任何cells之前,调用这个方法或者registerNib:forCellReuseIdentifier:
    方法去告诉tableView怎样去创建一个新的cell.如果一直指定类型的cell目前不在重用队列中,这个tableView会自动使用提供的信息去创建一个新的cell对象。

    If you previously registered a class or nib file with the same reuse identifier, the class you specify in the cellClass parameter replaces the old entry. You may specify nil for cellClass if you want to unregister the class from the specified reuse identifier.

    如果你之前使用了相同的重用标识注册了一个类或者nib文件,那这个类也就是你指定的cellClass这个参数会替换掉原来的条目(相当于下面绿色的代码)。如果你想用指定的重用标识不注册类的话,你可以在cellClass参数中指定nil。

    Availability

    Available in iOS 6.0 and later.

        [tableView registerClass:[UITableViewCellA class] forCellReuseIdentifier:@"city"];
        [tableView registerClass:[UITableViewCellB class] forCellReuseIdentifier:@"city"];
    

    相关文章

      网友评论

          本文标题:认识 - registerClass:forCellReuseI

          本文链接:https://www.haomeiwen.com/subject/tiqkkttx.html