Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
479 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 Reply

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类型)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...