iOS UITableViewCell Reuse Does Not Work (swift)

Asked 2 months ago, Updated 2 months ago, 3 views

I am creating a Twitter client using Swift from Xcode7beta5.
I use UITableViewCell to display the timeline, but it doesn't work.
Here's the code:

 functableView(tableView:UITableView, cellForRowAtIndexPath:NSIndexPath) ->UITableViewCell{

    varcell=tableView.dueReusableCellWithIdentifier("Cell", forIndexPath:indexPath) as? UITableViewCell
        print ("nil")
    Timeline Display Processing
    Return cell!

As for the condition, if you pinch the breakpoint in the queueReusableCellWithIdentifier part, it stops at this line, so it seems that this part has been reached."Also, the UITableViewCell is deployed on the StoryBoard, and the identifier is also ""
Breakpoints are inserted in the next line of the queueReusableCellWithIdentifier, but
in the next line. It didn't reach it, and when I stepped in at the requestReusableCellWithIdentifier, it was still
Get out of the breakpoint without anything happening.
I'm still studying iOS application development, so there may be a simple mistake, but I appreciate your cooperation.


2022-09-30 13:51

1 Answers

The following may not be the answer.I'll refuse it in advance.For

I use UITableViewCell to display the timeline, but it doesn't work.

It's because I don't know what kind of phenomenon is causing you to think it's "no good."

I think you should rewrite the code you provided like this.

 functableView(tableView:UITableView, cellForRowAtIndexPath:NSIndexPath) ->UITableViewCell{

    letcell=tableView.dueReusableCellWithIdentifier("Cell", forIndexPath:indexPath) as!UITableViewCell
    // Timeline Display Processing
    return cell

UITableView Class Reference

According to this, the return value of dueReusableCellWithIdentifier(_:forIndexPath:) is

Return Value
AUITableViewCell object with the associated reuse identifier.This method always returns a valid cell.

It is not an optional type, so it will not be nil.Also, although the type is AnyObject, it is certain that it is actually UITableViewCell, so you don't have to consider the possibility that the return value is nil or not UITableViewCell.

I would appreciate it if you could explain what unintended symptoms occur after making the above corrections.

2022-09-30 13:51

If you have any answers or tips

© 2022 OneMinuteCode. All rights reserved.