【发布时间】:2018-07-07 16:15:24
【问题描述】:
我有一个包含三个TableViews 的应用程序,每个应用程序都位于一个单独的ViewController 中。我想将数据从firstVC 传递到secondVC 到thirdVC。俱乐部 -> 会员 -> 交易。如果只有一个俱乐部,没有问题。
第二社里有第二社的成员,必须是这样的。
问题
但如果用户点击会员,则在第一家具乐部的indexPath上有来自第一家具乐部的会员的交易。
我的想法
因此,我必须将俱乐部也纳入交易。但我的解决方案只是抛出了错误。
所以也许你有一个很好的解决方案。我在这里找到了解决方案,但这对我没有帮助。
这是我的TableView 代码:
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return member?.transactions?.count ?? 0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableViewTransaction.dequeueReusableCell(withIdentifier: "transactionCell", for: indexPath)
if let transaction = member?.transactions?[indexPath.row] {
cell.textLabel?.text = transaction.reason
let moneystring = String(transaction.money)
cell.detailTextLabel?.text = moneystring + " Fr."
if transaction.money < 0.0 {
cell.detailTextLabel?.textColor = UIColor.red
}
if transaction.money > 0.0 {
cell.detailTextLabel?.textColor = UIColor(red: 0, green: 110/255, blue: 0, alpha: 0.8)
}
}
return cell
}
俱乐部获取:
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate
else {
return
}
let managedContext = appDelegate.persistentContainer.viewContext
let fetchrequest: NSFetchRequest <Verein> = Verein.fetchRequest()
do {
clubs = try managedContext.fetch(fetchrequest)
tableViewClub.reloadData()
} catch {
print("Could not fetch")
会员获取:
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {
return
}
let managedContext = appDelegate.persistentContainer.viewContext
let fetchrequest: NSFetchRequest<Member> = Member.fetchRequest()
do {
members = try managedContext.fetch(fetchrequest)
self.tableViewMember.reloadData()
} catch {
print("Could not fetch")
}
应用说明-
【问题讨论】:
-
你遇到了什么错误
-
@V_rohit club.members 没有会员交易
-
你能展示你的数据模式吗?l(即你定义的对象)以及你用来填充它的数据示例。以及您看到的错误。
-
@AshleyMills 我将核心数据模型添加到问题中
-
@AshleyMills 我的强项是显示交易,他们属于哪个俱乐部,因为我只是寻找会员。我想将 member.transactions 设为 club.members.transactions,这给了我一个错误,即这不是它的成员
标签: ios swift xcode uitableview core-data