2016-01-20 48 views
0

多元Tableviews上的应用程序,现在有希望实现,因为双tableview,其将用户信息转换成基于它们撤回数据两个独立tableviews什么工作,但我停留在此刻。我一直在努力想办法做到这一点,但现在我发现的大部分内容都不是我所期待的。我确定一切都正确连接,让tableview产生自定义单元格,并且所有东西都有一个类,但我仍然没有出现tableviewcells'可能由于此代码区域,但我不确定如何进展。的我在哪里例子如下:一个页面iPad应用

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

哪里是你的numberOfSection和numberOfRows:切入口的方法呢? –

+0

谢谢你在LucaD检查,但我认为下面的答案应该基于我所看到的:)我似乎有道理,如果我还有其他问题,我会尝试在本文中进一步询问。 – cruelty

回答

1

你可以做到这一点有:

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

    if tableView == tableOutletHere { 
     // initialize cell here 

     returnCell = cell 
    } 

    if tableView == tableOutletHere { 
     // initialize cell here 

     returnCell = cell 
    } 

    ... 
} 

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    var returnValue: Int = 0 

    if tableView == tableOutletHere { 
     returnValue = array1.count 
    } 

    if tableView == tableOutletHere { 
     returnValue = array2.count 
    } 

    ... 

    return returnValue 
} 
+0

我认为这正是我正在寻找的:)看起来像我的问题是我没有正确地设置var,也没有在第二个tableview的section中做numberOfRows!谢谢如果我还有其他问题,我会问这里! – cruelty

+0

@cruelty当然!不要忘记提高答案;) – iamalizade

相关问题