Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

swift 3 UITableView

I'm a newbie.
But I do not understand why the UITableView was not all elements loads (10 element in array).
With Xcode7 works but with Xcode8 (Swift 3) no.
I rewrote the code but to no avail: one element is being loaded ...

This is the code inside the UIViewController (with extension UITableViewDelegate, UITableViewDataSource)

CODE:

// MARK: UITableView
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return commentArray.count
}

// cell height
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
    return UITableViewAutomaticDimension
}

func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
    return true  
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let cell = mytableView.dequeueReusableCell(withIdentifier: "CellComment", for: indexPath ) as! commentCell


    // connect objects with our information from arrays
    cell.usernameBtn.setTitle(usernameArray[indexPath.row], for: UIControlState.normal)
    cell.usernameBtn.sizeToFit()
    cell.commentLbl.text = commentArray[indexPath.row]
    return cell
}

I think the problem is in the cellForRowAt....
I also have the following error:

BFTask caught an exception in the continuation block. This behaviour is discouraged and will be removed in a future release. Caught Exception: Invalid index path for use with UITableView. Index paths passed to table view must contain exactly two indices specifying the section and row. Please use the category on NSIndexPath in UITableView.h if possible.

I do not understand. Does anyone have an idea? Thank you

like image 581
CHRIS Avatar asked Jul 18 '26 02:07

CHRIS


1 Answers

You need to use following lines inside CellForRowAt IndexPath:

let cellIdentifier = "CellComment"
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier) as UITableViewCell?
like image 185
Mehul Solanki Avatar answered Jul 20 '26 17:07

Mehul Solanki



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!