2016-03-30 4 views
1

Я также сталкиваюсь с той же проблемой, о которой говорилось выше. Может ли кто-нибудь помочь мне в этом? Я определил свои NSMutableDictionary как результаты. И, напечатав его, я получил результат, как показано ниже:Невозможно подстроить значение типа NSMutableDictionary с индексом типа String

Ниже приведены значения в «результаты» 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;}] 

Мне нужно, чтобы заполнить эти значения в виде таблицы таким образом, что имя должно быть в значении nameLabel клеток, обратная связь в feedbackLabel значения ячейки. Как это сделать? Я пробовал все возможные вещи. Но не в состоянии получить решение.

Это мой полный код.

Фонд импорта класс 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() 
} 

}

+0

Там нет вопроса «упоминалось выше». Какая у вас проблема? –

+0

В этом я пытаюсь получить доступ к «результатам» и переместить его ниже функции. func tableView (tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier ("FeedbackIdentifierCell", forIndexPath: indexPath) как! FeedbackIdentifierCell cell.numberLabel.text = self.results ["Feedback"] as? String // Мне нужно заполнить всю обратную связь в представлении таблицы. Но получение ошибки как «Невозможно подстроить значение типа NSMutableDictionary с индексом типа String» return cell } –

+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"] 
    … 
Смежные вопросы