UITableView in Swift

前端 未结 17 1391
滥情空心
滥情空心 2020-12-04 08:09

I\'m struggling to figure out what\'s wrong with this code snippet. This is currently working in Objective-C, but in Swift this just crashes on the first line of the method.

17条回答
  •  遥遥无期
    2020-12-04 08:21

    I have done in following way: to show detailTextLabel. text value

     func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    
        let CellIdentifier: String = "cell"
    
        var cell = tableView.dequeueReusableCellWithIdentifier(CellIdentifier) as? UITableViewCell
    
        if cell == nil {
            cell = UITableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: CellIdentifier)
        }
    
        //cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator
    
        // parse the value of records
        let dataRecord = self.paymentData[indexPath.row] as! NSDictionary
    
        let receiverName = dataRecord["receiver_name"] as! String
        let profession = dataRecord["profession"] as! String
        let dateCreated = dataRecord["date_created"] as! String
        let payAmount = dataRecord["pay_amount"] as! String
    
        println("payment \(payAmount)")
        cell!.textLabel?.text = "\(receiverName)\n\(profession)\n\(dateCreated)"
        cell!.detailTextLabel?.text = "$\(payAmount)"
        cell!.textLabel?.numberOfLines = 4
    
        return cell!
    
    }// end tableview
    

提交回复
热议问题