2016-03-30 7 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 { cell = tableView.dequeueReusableCellWithIdentifier( "FeedbackIdentifierCell"、forIndexPath:indexPath)を次のようにします。 FeedbackIdentifierCell cell.numberLabel.text = self.results ["Feedback"] as? String //すべてのフィードバックをtableviewに読み込む必要があります。しかし、 "String型のインデックスを持つNSMutableDictionary型の値を添字できません" 戻りセル } –

+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"] 
    … 
関連する問題