gpt4 book ai didi

ios - 如何在iOS中重新加载 TableView Controller 中的数据?

转载 作者:行者123 更新时间:2023-11-30 11:45:25 27 4
gpt4 key购买 nike

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

这是我的代码:

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);
}
}

主屏幕

个人资料屏幕

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

如何解决这个问题?

最佳答案

这是 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
}
}
}

关于ios - 如何在iOS中重新加载 TableView Controller 中的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48887741/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com