我在Parse.com的tableView中使用cellForRowAtIndexPath时遇到问题我正在运行的代码是:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("ListadoInventarioCell", forIndexPath: indexPath) as UITableViewCell
var sectionTitle:String = timelineData1.objectAtIndex(indexPath.section) as String
var sectionAnimals:Array = porBodega[sectionTitle]!
// This is the line with problems
var animal:String = sectionAnimals.objectAtIndex(indexPath.row) as String
cell.textLabel?.text = animal
}
问题是变量porBodega是String类型的Dictionary:ArrayOfPFObject,因此sectionAnimals是PFObjects的数组。如果我做println(porBodega),我明白了:
[Oficina: [
<InventarioObjetos:wObhxQ98oz:(null)> {
Bodega = Oficina;
Categoria = "Equipo de monta\U00f1a";
Descripcion = Chalecos;
FechaDeEntrada = "2012-04-01 19:44:00 +0000";
Marca = "O'rageous";
Modelo = "VM-001";
NumeroDeInventario = CSOV002;
NumeroDeSerie = NA;
Status = Usado;
Tamano = M;
},
<InventarioObjetos:u3Yn80lXU8:(null)> {
Bodega = Oficina;
Categoria = "Equipo de monta\U00f1a";
Descripcion = Chalecos;
FechaDeEntrada = "2012-04-01 19:44:00 +0000";
Marca = "O'rageous";
Modelo = "VM-001";
NumeroDeInventario = CSOV003;
NumeroDeSerie = NA;
Status = Usado;
Tamano = M;
}
]]
所以我不知道如何从我的一个对象中获取特定数据,比如变量Modelo,然后在单元格文本标签中设置它。任何想法??
答案 0 :(得分:1)
修改强>
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("ListadoInventarioCell", forIndexPath: indexPath) as UITableViewCell
var sectionTitle:String = timelineData1.objectAtIndex(indexPath.section) as String
var sectionAnimals:Array = porBodega[sectionTitle]!
let animal:PFObject = sectionAnimals[indexPath.row] as PFObject
cell.textLabel?.text = animal.objectForKey("modelo") as String
}