gpt4 book ai didi

ios - 无法使用 String 类型的索引下标 NSMutableDictionary 类型的值

转载 作者:行者123 更新时间:2023-11-28 08:41:58 25 4
gpt4 key购买 nike

我也遇到了上面提到的问题。有人可以帮我吗?我已将我的 NSMutableDictionary 定义为结果。通过打印它,我得到了如下结果:

下面是“resultsNSMutableDictionary 中的值。

[{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;}]

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

这是我的完整代码。

导入基金会反馈 View Controller 类: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()
}

最佳答案

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

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"]

关于ios - 无法使用 String 类型的索引下标 NSMutableDictionary 类型的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36299799/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com