无法使用String

时间:2016-03-30 04:36:05

标签: ios swift

我也面临着上述同样的问题。有人可以帮助我吗? 我已将NSMutableDictionary定义为结果。通过打印我得到如下结果:

以下是“结果NSMutableDictionary中的值。

[{Name = 4480101010;Feedback = goo;FeedbackID = 186;FeedbackOn = "18-Mar-2016 11:26";IsFrom = 1;UserName = "Bernie Killian";RequestID = 1531;}

{Name = 4480101010;Feedback = supr;FeedbackID = 172;FeedbackOn = "09-Mar-2016 08:04";IsFrom = 1;UserName = rajesh;RequestID = 1445;},{Name = 4480101010;Feedback = supr;FeedbackID = 170;FeedbackOn = "09-Mar-2016 08:00";IsFrom = 1;UserName = rajesh;RequestID = 1444;},{Name = 4480101010;Feedback = "all works fine";FeedbackID = 158;FeedbackOn = "08-Mar-2016 17:21";IsFrom = 1;UserName = "Mahendra Suthar";RequestID = 1429;}]

我需要在表格视图中填充这些值,使得Name应该在nameLabel单元格值中,反馈在feedbackLabel单元格值中。怎么做?我已经尝试了所有可能的事情。但无法得到解决方案。

这是我的完整代码。

导入基金会 class FeedbackViewController:UIViewController,UITableViewDelegate,UITableViewDataSource {

@IBOutlet weak var tableView: UITableView!
var feedbackResults = [String]()
var prefectCount : Int = 0
var abhyasiCount : Int = 0
var prefectResults = [NSMutableDictionary]()
var abhyasiResults = [NSMutableDictionary]()
var selectedIndex : Int = 0
var totalCount : Int = 1

override func viewDidLoad() {
    super.viewDidLoad()
    tableView.delegate = self
    tableView.dataSource = self
    reloadTable()
    let appid : String = NSUserDefaults.standardUserDefaults().objectForKey("appID") as! String
    Server.sendGet(URL.getUserFeedbackInformation(appid), completionHandler: self.feedbackCompletionHandler)
}

@IBAction func onFeedbackChanged(sender: AnyObject) {
    if sender.selectedSegmentIndex == 0 {
        self.selectedIndex = 0
    }else{
        self.selectedIndex = 1
    }
    print(selectedIndex)
}

func feedbackCompletionHandler(data: NSData?, response: NSURLResponse?, error: NSError?){
    dispatch_async(dispatch_get_main_queue(), {
        // code here
        let responseStr = Server.dataToNSArray(data)
        for eachFeedback in responseStr!{
            if eachFeedback["IsFromPerceptor"] as! NSNumber == 1   {
                self.abhyasiCount++
                self.abhyasiResults.append(eachFeedback as! NSMutableDictionary)

            }
            else
            {
                self.prefectCount++
                self.prefectResults.append(eachFeedback as! NSMutableDictionary)

            }
        }

        self.reloadTable()

    })

}

// START Table View
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1

}


func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    print(self.selectedIndex)
    if self.selectedIndex == 0 {
        self.totalCount = self.abhyasiCount
    }else{
        self.totalCount =  self.prefectCount
    }
    return self.totalCount

}


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

    let cell = tableView.dequeueReusableCellWithIdentifier("FeedbackIdentifierCell", forIndexPath: indexPath) as! FeedbackIdentifierCell
    cell.numberLabel.text = abhyashiResults[“FeedbackID”] as? String
    cell.nameLabel.text = abhyashiResults[“Name”] as? String
    cell.feedbackLabel.text = abhyashiResults[“Feedback”] as? String
    cell.dateLabel.text = abhyashiResults[“FeedbackOn”] as? String

    return cell

}

func reloadTable() {
    tableView.reloadData()
}
override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
}

}

1 个答案:

答案 0 :(得分:0)

您提供的结果值是一个字典数组,而不是字典本身。根据您的评论,您似乎需要从数组中提取特定值。您可能可能根据传递给您的索引路径执行此操作:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("FeedbackIdentifierCell", forIndexPath: indexPath) as! FeedbackIdentifierCell

    let valueForCell = results[indexPath.row]
    cell.numberLabel.text = valueForCell["Feedback"]
    …