2016-01-20 23 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

相關問題