2015-04-23 78 views
0

我是新来编码,所以希望下面的说法很有道理!从阵列拉动静态图像

我在Xcode中有一个数组放在名为'numbersData'的文件中。

我在其他地方使用可重复使用的表格单元格,并希望根据其索引路径从此数组中为每个单元格拉入信息。

我没有这样做的文字....但是我发现很难在单元格中填充UIImage视图。

我的数组使用标识符“badge”具有图像的名称。我已经保存在images.xcassets图像。

这里是我在我的表视图控制器代码:

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

    let cell = tableView.dequeueReusableCellWithIdentifier("StoryCell") as NumbersTableViewCell 

    cell.titleLabel.text = numbersData[indexPath.row]["title"] as? String 
    cell.titleLabel2.text = numbersData[indexPath.row]["title2"] as? String 
    cell.summaryLabel.text = numbersData[indexPath.row]["subtitle"] as? String 

    cell.articleImageView.image = //This is where I am stuck! 
    cell.delegate = self 

    return cell 
} 

我的数组是这样的:

[ 
    "id": 1, 
    "title": "BODMAS - The Order Of", 
    "title2": "Things", 
    "subtitle": "orem ipsum and all that malarky and not of the hipster variety", 
    "segue": "NumbersSegue1", 
    "badge": "cat-pic" 
], 
[ 
    "id": 2, 
    "title": "Rearranging & Solving", 
    "title2": "Equations", 
    "subtitle": "orem ipsum and all that malarky and not of the hipster variety", 
    "segue": "NumbersSegue2", 
    "badge": "numbersPicture2" 
], 

任何帮助将是惊人的!

回答

1

尝试这样的:

cell.articleImageView.image = UIImage(named: (numbersData[indexPath.row]["badge"] as? String)!) 
+0

谢谢!它看起来不错,但我不断得到一个奇怪的错误,说“可选类型'字符串'的值不解开,并问我是否打算使用'?'或'!'....这似乎很奇怪我作为一个问号正在使用! – user3324594

+0

也许一个xcode的bug ??? – user3324594

+0

我已编辑字典返回一个可选的,所以你需要解开它之前铸造 –