现在使用我希望实现的双tableview
项目来处理应用程序,根据他们撤回的数据将用户信息拆分为两个单独的表视图,但我现在陷入困境。我一直试图想办法这样做一段时间,但我发现的大部分页面都不是我想要的。我确保所有内容都已正确连接,以便tableview
生成自定义单元格,并且所有内容都有类,但我仍然没有tableviewcells
'提出自己可能是由于这个代码区域,但我不确定如何进步。我在哪里的例子如下:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let entityDeckDescription = NSEntityDescription.entityForName("Deck", inManagedObjectContext: context)
var cell = UITableViewCell()
if tableView == otherCardList {
let cell: cardDetails = otherCardList.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! cardDetails
var cardCount = 0
var myDeckCards: DeckCards?
let listed = frc.objectAtIndexPath(indexPath) as! Cards
cell.cardCount.text = ""
let deckCardsSet = listed.cardselections
print("The set of DeckCards for that Card is \(deckCardsSet.count)")
for eachDeckCard in listed.cardselections{
let myDeckCard = eachDeckCard as! DeckCards
if myDeckCard.cardsstored == entityDeckDescription {
// There is already a DeckCard object for this Card and currentDeck
myDeckCards = eachDeckCard as? DeckCards
cardCount = (myDeckCards?.numberSelected!.integerValue)!
if cardCount == 0 {
cell.cardCount.text = ""
} else {
cell.cardCount.text = "" + cardCount.description
}
}
}
switch (listed.cardType) {
case 1:
cell.cardAttack?.text = "*"
cell.cardAttack?.textColor = UIColor.redColor()
cell.cardHealth?.text = "*"
cell.heathLabel?.textColor = UIColor(red: 0x22/255, green: 0x63/255, blue: 0x29/255, alpha: 1.0)
cell.cardHealth?.textColor = UIColor(red: 0x22/255, green: 0x63/255, blue: 0x29/255, alpha: 1.0)
cell.cardType?.text = "Spell"
case 2:
cell.cardAttack?.text = listed.attack.stringValue
cell.heathLabel?.textColor = UIColor.blackColor()
cell.cardHealth?.textColor = UIColor.blackColor()
cell.cardHealth?.text = listed.health.stringValue
cell.cardType?.text = "Weapon"
cell.cardAttack?.text = listed.attack.stringValue
default:
cell.cardAttack?.text = listed.attack.stringValue
cell.heathLabel?.textColor = UIColor(red: 0x22/255, green: 0x63/255, blue: 0x29/255, alpha: 1.0)
cell.cardAttack?.textColor = UIColor.redColor()
cell.cardHealth?.text = listed.health.stringValue
cell.cardHealth?.textColor = UIColor(red: 0x22/255, green: 0x63/255, blue: 0x29/255, alpha: 1.0)
cell.cardType?.text = "Minion"
}
cell.cardName?.text = listed.name as String
cell.cardCost?.text = listed.cost.stringValue
switch (listed.rarity) {
case 1:
cell.cardRarity?.text = "Legendary"
cell.cardRarity?.textColor = UIColor.orangeColor()
case 2:
cell.cardRarity?.text = "Epic"
cell.cardRarity?.textColor = UIColor.purpleColor()
case 3:
cell.cardRarity?.text = "Rare"
cell.cardRarity?.textColor = UIColor.blueColor()
case 4:
cell.cardRarity?.text = "Common"
cell.cardRarity?.textColor = UIColor.grayColor()
default:
cell.cardRarity?.text = "Starter"
cell.cardRarity?.textColor = UIColor.blackColor()
}
switch (listed.cardClass) {
case 1:
cell.cardName?.textColor = UIColor(red: 0xbe/255, green: 0x23/255, blue: 0x0f/255, alpha: 1.0)
case 2:
cell.cardName?.textColor = UIColor.blueColor()
case 3:
cell.cardName?.textColor = UIColor(red: 0x75/255, green: 0x47/255, blue: 0x19/255, alpha: 1.0)
case 4:
cell.cardName?.textColor = UIColor(red: 0xFF/255, green: 0x80/255, blue: 0x00/255, alpha: 1.0)
case 5:
cell.cardName?.textColor = UIColor(red: 0x22/255, green: 0x63/255, blue: 0x29/255, alpha: 1.0)
case 6:
cell.cardName?.textColor = UIColor.brownColor()
case 7:
cell.cardName?.textColor = UIColor(red: 0x5E/255, green: 0x03/255, blue: 0x8F/255, alpha: 1.0)
case 8:
cell.cardName?.textColor = UIColor(red: 0x01/255, green: 0xA9/255, blue: 0xDB/255, alpha: 1.0)
case 9:
cell.cardName?.textColor = UIColor.magentaColor()
default:
cell.cardName?.textColor = UIColor.blackColor()
}
return cell
} else if tableView == classCardList {
let cell: cardDetails = classCardList.dequeueReusableCellWithIdentifier("classcell", forIndexPath: indexPath) as! cardDetails
var cardCount = 0
var myDeckCards: DeckCards?
let listed = classfrc.objectAtIndexPath(indexPath) as! Cards
cell.cardCount.text = ""
let deckCardsSet = listed.cardselections
print("The set of DeckCards for that Card is \(deckCardsSet.count)")
for eachDeckCard in listed.cardselections{
let myDeckCard = eachDeckCard as! DeckCards
if myDeckCard.cardsstored == entityDeckDescription {
// There is already a DeckCard object for this Card and currentDeck
myDeckCards = eachDeckCard as? DeckCards
cardCount = (myDeckCards?.numberSelected!.integerValue)!
if cardCount == 0 {
cell.cardCount.text = ""
} else {
cell.cardCount.text = "" + cardCount.description
}
}
}
switch (listed.cardType) {
case 1:
cell.cardAttack?.text = "*"
cell.cardAttack?.textColor = UIColor.redColor()
cell.cardHealth?.text = "*"
cell.heathLabel?.textColor = UIColor(red: 0x22/255, green: 0x63/255, blue: 0x29/255, alpha: 1.0)
cell.cardHealth?.textColor = UIColor(red: 0x22/255, green: 0x63/255, blue: 0x29/255, alpha: 1.0)
cell.cardType?.text = "Spell"
case 2:
cell.cardAttack?.text = listed.attack.stringValue
cell.heathLabel?.textColor = UIColor.blackColor()
cell.cardHealth?.textColor = UIColor.blackColor()
cell.cardHealth?.text = listed.health.stringValue
cell.cardType?.text = "Weapon"
cell.cardAttack?.text = listed.attack.stringValue
default:
cell.cardAttack?.text = listed.attack.stringValue
cell.heathLabel?.textColor = UIColor(red: 0x22/255, green: 0x63/255, blue: 0x29/255, alpha: 1.0)
cell.cardAttack?.textColor = UIColor.redColor()
cell.cardHealth?.text = listed.health.stringValue
cell.cardHealth?.textColor = UIColor(red: 0x22/255, green: 0x63/255, blue: 0x29/255, alpha: 1.0)
cell.cardType?.text = "Minion"
}
cell.cardName?.text = listed.name as String
cell.cardCost?.text = listed.cost.stringValue
switch (listed.rarity) {
case 1:
cell.cardRarity?.text = "Legendary"
cell.cardRarity?.textColor = UIColor.orangeColor()
case 2:
cell.cardRarity?.text = "Epic"
cell.cardRarity?.textColor = UIColor.purpleColor()
case 3:
cell.cardRarity?.text = "Rare"
cell.cardRarity?.textColor = UIColor.blueColor()
case 4:
cell.cardRarity?.text = "Common"
cell.cardRarity?.textColor = UIColor.grayColor()
default:
cell.cardRarity?.text = "Starter"
cell.cardRarity?.textColor = UIColor.blackColor()
}
switch (listed.cardClass) {
case 1:
cell.cardName?.textColor = UIColor(red: 0xbe/255, green: 0x23/255, blue: 0x0f/255, alpha: 1.0)
case 2:
cell.cardName?.textColor = UIColor.blueColor()
case 3:
cell.cardName?.textColor = UIColor(red: 0x75/255, green: 0x47/255, blue: 0x19/255, alpha: 1.0)
case 4:
cell.cardName?.textColor = UIColor(red: 0xFF/255, green: 0x80/255, blue: 0x00/255, alpha: 1.0)
case 5:
cell.cardName?.textColor = UIColor(red: 0x22/255, green: 0x63/255, blue: 0x29/255, alpha: 1.0)
case 6:
cell.cardName?.textColor = UIColor.brownColor()
case 7:
cell.cardName?.textColor = UIColor(red: 0x5E/255, green: 0x03/255, blue: 0x8F/255, alpha: 1.0)
case 8:
cell.cardName?.textColor = UIColor(red: 0x01/255, green: 0xA9/255, blue: 0xDB/255, alpha: 1.0)
case 9:
cell.cardName?.textColor = UIColor.magentaColor()
default:
cell.cardName?.textColor = UIColor.blackColor()
}
}
return cell
}
我很确定这是引起问题的代码区域,但如果你们认为它在其他地方,我们可以找出问题的来源。我仍然是编码的新手,并且总是尽可能地学习。
答案 0 :(得分:1)
您可以通过以下方式实现此目的:
<?xml version="1.0" encoding="UTF-8"?>2