zoukankan      html  css  js  c++  java
  • Subclassing UITableViewCell(15)

    注意属性都是weak

    // Load the NIB file
    UINib *nib = [UINib nibWithNibName:@"HomepwnerItemCell" bundle:nil];

    // Register this NIB which contains the cell

    [[self tableView] registerNib:nib  forCellReuseIdentifier:@"HomepwnerItemCell"]; 

    // Get the new or recycled cell

    HomepwnerItemCell *cell = [tableView  dequeueReusableCellWithIdentifier:@"HomepwnerItemCell"]; 

    xib与nib之间的关系

    Let’s go back to the UINib class you used when loading HomepwnerItemCell.xib. An instance of UINib knows how to read a XIB file. (Remember, XIB and NIB are used interchangeably; technically, an application loads NIBs, but we work with XIBs, so it’s easier to call them that.)

    An instance of UINib is created with the contents of a XIB file. It loads the data in that file and holds on to it as long as it lives. When it is sent the message instantiateWithOwner:options:, the UINib parses that data: all of the archived objects come alive, and all of the connections are established. (The object passed as the first argument is the File's Owner.)

    In Chapter 10, you loaded a XIB file by sending the message loadNibNamed:owner:options: to the main NSBundle without ever using UINib. Well, loadNibNamed:owner:options: uses UINib under the hood. It creates an instance of UINib and sends it the message instantiateWithOwner:options:, relaying the options and owner arguments.

    Both of these methods return an NSArray. This array contains all of the top-level objects in the XIB file (the ones that aren’t under a disclosure tab in the outline view of the XIB). When you register a XIB file with a table view, it scans this array for an instance of UITableViewCell or a subclass of it and returns it to your data source.

    Since the table view just scans the XIB file for a UITableViewCell, it is important that you only put one instance of UITableViewCell in a XIB file used for this purpose. Otherwise, the table view will get confused and throw an exception. 

  • 相关阅读:
    如果你也用过struts2.简单介绍下springMVC和struts2的区别有哪些?
    人事面试
    人事面试
    人事面试
    java 数字和日期处理
    jsp文件导包
    asp.net MVC中使用Autofac小结 (遇到的最傻错误: 没有为该对象定义无参数的构造函数)
    Asp.net MVC 单元测试 简要笔记
    NewtonJson中转义的斜杠和多余的引号处理
    RecyclerView onTouch & onClick 触摸事件与点击事件
  • 原文地址:https://www.cnblogs.com/zhangjl/p/3634625.html
Copyright © 2011-2022 走看看