dequeueReusableCellWithIdentifier always return non nil?

前端 未结 2 1927
灰色年华
灰色年华 2021-01-06 19:54

In the classic pattern below the returned cell from dequeueReusableCellWithIdentifier is always non nil. Why? Shouldn\'t we have to al

相关标签:
2条回答
  • 2021-01-06 20:38

    If you're using storyboard and set the UITableViewCell's Identifier to the identifier to the one you are using in dequeueReusableCellWithIdentifier ("AlbumCell" in your case) in the storyboard file, the UITableView will always create cells for you. I guess this is a feature of storyboard. If the identifier can't be found in your storyboard, then you need to create cells manually.

    0 讨论(0)
  • 2021-01-06 20:50

    I know it is possible for the return of the cell to be nil and you should check for it. Usually this will not be the case as you should get a cell created for you from your identifier you supplied. If you for instance did not have the identifier correct and the pool was empty I believe that is the case where you would get nil and you could do an aloc init to create a new cell. Also I should add the prototype cell you create in xcode is what creates the cell and that is why it should start as non nil and you don't have to create one.

    To better answer this go to iTunes and go to the course iPad and iPhone Application Development - Paul Hegarty - Stanford CS193p course. Go to lecture (25) 9. Table Views go to 26 minutes in.

    0 讨论(0)
提交回复
热议问题