2016-06-11 3 views
-2

Я пытаюсь получить данные из основных данных с помощью ячеек таблицы, но когда данные перезагружаются, каждый элемент в ячейке принимает отдельные ячейки, я надеюсь, вы понимаете, что я имею в виду.перезагрузить данные из основных данных в swift

это код, который я думаю, что это ошибка

override func viewWillAppear(animated: Bool) { 
     super.viewWillAppear(animated) 

     //1 
     let appDelegate = 
      UIApplication.sharedApplication().delegate as! AppDelegate 

     let managedContext = appDelegate.managedObjectContext 

     //2 
     let fetchRequest = NSFetchRequest(entityName: "ShopList") 

     //3 
     do { 
      let results = 
       try managedContext.executeFetchRequest(fetchRequest) 
      people = results as! [NSManagedObject] 

      let results2 = 
       try managedContext.executeFetchRequest(fetchRequest) 
      ids = results2 as! [NSManagedObject] 


     } catch let error as NSError { 
      print("Could not fetch \(error), \(error.userInfo)") 
     } 
    } 

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
     let cell = self.tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! itemsList 


     let shopList = people[indexPath.row] 
     cell.items!.text = shopList.valueForKey("name") as? String 

     let shopList2 = ids[indexPath.row] 
     cell.itemsId!.text = shopList2.valueForKey("logo") as? String 



     return cell 
    } 
+0

Что такое ошибка? – tbilopavlovic

+0

У меня есть 2 элемента в каждой ячейке, когда я извлекаю данные, 2 элемента в ячейке, перезагруженные в отдельных ячейках, каждый элемент принимает одну ячейку вместо двух элементов в одной ячейке. –

+0

Пожалуйста, вставьте код для метода 'cellForRowAtIndexPath..' – tbilopavlovic

ответ

0

Попробуйте это, если проблема все еще существует, пожалуйста, добавьте код для numberOfRowsInSection в вопросе

override func viewWillAppear(animated: Bool) { 
      super.viewWillAppear(animated) 

      //1 
      let appDelegate = 
       UIApplication.sharedApplication().delegate as! AppDelegate 

      let managedContext = appDelegate.managedObjectContext 

      //2 
      let fetchRequest = NSFetchRequest(entityName: "ShopList") 

      //3 
      do { 
       let results = 
        try managedContext.executeFetchRequest(fetchRequest) 
       people = results as! [NSManagedObject] 


      } catch let error as NSError { 
       print("Could not fetch \(error), \(error.userInfo)") 
      } 
     } 

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
      let cell = self.tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! itemsList 

      let shopList = people[indexPath.row] 
      cell.items!.text = shopList.valueForKey("name") as? String 
      cell.itemsId!.text = shopList.valueForKey("logo") as? String 

      return cell 
     } 
Смежные вопросы