从 NSDictionary Issue 调用特定的数据键值

Calling a specific data key value from NSDictionary Issue

从 cellForRowAtIndexPath 中的 NSDictionary 调用一个值,但我得到的数据 (parsedData) 为 nil。请问如何从 NSDictionary 键值中获取数据?

var dic1 = NSDictionary()

func parser(parser: NSXMLParser!, didStartElement elementName: String!, namespaceURI: String!, qualifiedName qName: String!, attributes attributeDict: [NSObject : AnyObject]!)
{
    element = elementName

    if (elementName as NSString).isEqualToString("info")
    {
        symbolStr = attributeDict["symbol"]! as NSMutableString
        offerlStr = attributeDict["offer"]! as NSMutableString

        dic1 = ["symbolName":symbolStr , "offerAmount":offerlStr]

        pariteArray.addObject(dic1)   
    }
}

func tableView(tableView: UITableView, numberOfRowsInSection section:    Int) -> Int {

    return pariteArray.count
}

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

    var parsedData: AnyObject? = dic1["symbolName"]?.indexPath
    var parsedData2: AnyObject? = dic1["offerAmount"]?.indexPath

    let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "MyTestCell")

    cell.textLabel?.text = parsedData as? String //nil
    cell.detailTextLabel.text = parsedData2 as? String //nil

    return cell
}

我不确定你想做什么,但我可以告诉你为什么你的代码是错误的。

在这里,您将 dic11 的值分配为 NSMutableString 个对象:

symbolStr = attributeDict["symbol"]! as NSMutableString
offerlStr = attributeDict["offer"]! as NSMutableString

dic1 = ["symbolName":symbolStr , "offerAmount":offerlStr]

稍后,您尝试访问 .indexPath 这些对象:

var parsedData: AnyObject? = dic1["symbolName"]?.indexPath
var parsedData2: AnyObject? = dic1["offerAmount"]?.indexPath

NSMutableString 没有 .indexPath.

我将在这里大胆猜测并假设您确实想要这样做:

var parsedData: AnyObject? = pariteArray[indexPath.row]["symbolName"]
var parsedData2: AnyObject? = pariteArray[indexPath.row]["offerAmount"]