如何在iOS中的表视图控制器中重新加载数据?

时间:2018-02-20 14:39:39

标签: ios swift uitableview

我在表视图控制器中重新加载数据时遇到问题。当我在主控制器中搜索记录时,它会显示该记录的配置文件详细信息。当我从个人资料屏幕返回时,主屏幕中的记录没有显示。它只显示一条记录,即之前选择的记录。

这是我的代码:

let tempDict:NSMutableDictionary = NSMutableDictionary();

var cardImg:UIImage!;
if(contactList.card_img_frontside != nil){
    cardImg = UIImage(data: contactList.card_img_frontside)!;
    tempDict.setObject(cardImg, forKey: kCardImgFront as NSCopying);
}
else{
    if let url = contactList.card_img_url{
        tempDict.setObject(url, forKey: kCardImgFront as NSCopying);
        tableView.reloadData();
    }
}

var cardImgBack:UIImage!;
if(contactList.card_img_back != nil){
    cardImgBack = UIImage(data: contactList.card_img_back)!;
    tempDict.setObject(cardImgBack, forKey: kCardImgBack as NSCopying)

}
else{
    if let url = contactList.card_img_url_back{
        tempDict.setObject(url, forKey: kCardImgBack as NSCopying);
    }
}

主屏幕

个人资料屏幕

点击个人资料屏幕上的后退按钮,显示如下:

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

这是numberOfRowsInSection ...

的代码
func tableView( _ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{

    var rowCount:Int?  = 0
    if(tableView == self.menuTableView){
        rowCount = self.menuOptions?.count;
    }
    else if(tableView == self.slideMenuTableView){
    rowCount = self.slideMenuArray?.count;
   }
    else if(self.isSearching == true){

        rowCount = self.filteredArray?.count;
   }
   else {
      if let controller = self.fetchResultController
      {
        let sections :Array = controller.sections!;
        let sectionInfo = sections[0] as NSFetchedResultsSectionInfo;
        rowCount = sectionInfo.numberOfObjects;

       }
     }
     return rowCount!;
}

这适用于cellForRowAtIndexPath ...

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
    var tableViewCell:UITableViewCell! ;
    if(tableView == self.tableView){
    let cellID : String = "CellIdentifier";
    var cell : MGSwipeTableCell! = tableView.dequeueReusableCell(withIdentifier: cellID) as? MGSwipeTableCell;
    if (cell == nil) {
        cell = (((Bundle.main.loadNibNamed("MGSwipeTableCell", owner: self, options: nil)! as NSArray).lastObject) as! MGSwipeTableCell);
            cell.delegate = self;
        self.configureCell(cell, indexPath: indexPath);
        tableViewCell = cell;
        cell.layer.cornerRadius = 5.5
     }
   }
 }