Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
459 views
in Technique[技术] by (71.8m points)

swift - 无法将类型'__NSCFString'(0x7fff87a89460)的值强制转换为'NSArray'(0x7fff87a8a310)(Could not cast value of type '__NSCFString' (0x7fff87a89460) to 'NSArray' (0x7fff87a8a310))

I'm extracting data from Mssql.

(我正在从Mssql提取数据。)

I want to print the data I received from the database to tableview, but I get the error "Could not cast value of type '__NSCFString' (0x7fff87a89460) to 'NSArray' (0x7fff87a8a310)".

(我想将我从数据库收到的数据打印到tableview,但是出现错误“无法将类型'__NSCFString'(0x7fff87a89460)的值强制转换为'NSArray'(0x7fff87a8a310)”。)

I assign the data to the value variable.

(我将数据分配给value变量。)

How can I solve the problem?

(我该如何解决这个问题?)

class MakaleController: UIViewController, UITableViewDataSource, UITableViewDelegate {
    @IBOutlet var makaleTable: UITableView!
    var stringvalue: [String] = []
 override func viewDidLoad() {
           super.viewDidLoad()
        let client = SQLClient.sharedInstance()!
             client.connect("...") { success in
           client.execute("SELECT Email FROM ...", completion: { (_ results: ([Any]?)) in
                          for table in results as! [[[String:AnyObject]]] {
                              for row in table {
                                  for (columnName, value) in row {
                                    self.stringvalue = value as! [String]
                                  }
                              }
                          }
                          client.disconnect()
                      })
                  }

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

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

   let cell:UITableViewCell = self.makaleTable.dequeueReusableCell(withIdentifier: "makalecell") as! UITableViewCell


        cell.textLabel?.text = self.stringvalue[indexPath.row]

        return cell
    }
    }
  ask by SH Yaz?l?m Geli?tirme translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

May be problem is here

(可能是这里的问题)

 self.stringvalue = value as! [String]

please do

(请做)

print(type(of:value))

value is a String type

(value是一个String类型)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...