dequeueReusableCellWithIdentifier never returns nil

前端 未结 4 547
臣服心动
臣服心动 2020-12-06 00:30

I am using a custom UITableViewCell in my UITableView but the problem is that the cell is never nil when calling the dequeueReusableCellWithIdentifier. Why is this ?

4条回答
  •  旧时难觅i
    2020-12-06 00:56

    Starting in iOS 5 when you use storyboards and your reuse identifier matches a prototype in your storyboard you will not get a nil returned from dequeueReusableCellWithIdentifier.

    From Apple Doc:

    Table View Programming Guide for iOS

    Creating and Configuring a Table View

    Populating a Dynamic Table View with Data

    If the dequeueReusableCellWithIdentifier: method asks for a cell that’s defined in a storyboard, the method always returns a valid cell. If there is not a recycled cell waiting to be reused, the method creates a new one using the information in the storyboard itself. This eliminates the need to check the return value for nil and create a cell manually.

    You can log the cell address to prove to your self they are being reused. But don't ship with the logging it will really slow up your table.

    NSLog(@"Deque Cell %p", cell);
    

    Better yet use breakpoint to log it.

    enter image description here

    $25 = 0x097f9850 

    If you just want the addresses

    enter image description here

    0x097f9850
    0x0a6a4a00
    0x0a3ad250
    0x0a3ae640
    0x0972a370
    

提交回复
热议问题