Ios 主详细视图应用程序
我正在尝试创建一个主细节视图应用程序&我有点卡住了 我有一个表视图,其中有100个Ios 主详细视图应用程序,ios,iphone,swift,uitableview,master-detail,Ios,Iphone,Swift,Uitableview,Master Detail,我正在尝试创建一个主细节视图应用程序&我有点卡住了 我有一个表视图,其中有100个DynamicPrototype单元格显示条形图,当我点击单元格时,我想显示有关该条形图的更多信息 我的问题是如何将不同的数据如标签和图像填充到详细视图中,并为每个单元格更改它们我点击以表示正确的数据 MyDetailview是一个带有StaticCells的TableViewController,如下所示: 我使用的是Swift 2.3和Xcode 8.1 我创建了一个类来表示我的DetailView数据: B
DynamicPrototype
单元格
显示条形图,当我点击单元格
时,我想显示有关该条形图的更多信息
我的问题是如何将不同的数据
如标签
和图像
填充到详细视图
中,并为每个单元格更改它们
我点击以表示正确的数据
MyDetailview
是一个带有StaticCells
的TableViewController
,如下所示:
我使用的是Swift 2.3和Xcode 8.1
我创建了一个类来表示我的DetailView数据:
BarProfile.Swift:
我的BarsTableView
如下所示:
BARSTABLEVEWCONTROLLER.Swift:
我没有找到一个教程来展示我真正想要的,我希望在这里找到答案,因为detailView是每个项目或应用程序的基础
我不知道如何继续下去,对此我很沮丧
感谢您的帮助:)您可以通过
prepareforsgue
函数将数据传递到详细信息视图,并在目标视图中设置变量或调用函数
下面是一个如何做到这一点的例子。这假设您用于显示“详细信息”的视图类型为DetailView
,并且来自master->detail的序列称为“BarsProfile”:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if(segue.identifier == "BarsProfile") {
if(segue.destination is DetailView) {
let destVC = segue.destination as! DetailView
// Set variables in Detail View here
// e.g. :
destVC.detailData = selectedData
}
}
}
展示你掌握的任何课程的
prepareForSegue
方法。我没有这个方法,所以你需要做更多的教程,然后问具体的问题。试试看:你为一个新手写得很好。别担心。我建议你看整个视频。太棒了,如果我这么做,我的老天爷还是老样子?我不明白这个问题。我的理解是,您希望在“主”视图的表中选择一行,这将打开相应的“详细”视图,并用所选项目的信息填充该视图。这是对的吗?是的@摇摇晃晃
import UIKit
class BarsTableViewController: UITableViewController,UISearchResultsUpdating,UISearchBarDelegate,UISearchDisplayDelegate{
@IBOutlet var tableViewController: UITableView!
// MARK : Data
var names = ["Shalvata",
"Markid",
"Litzman Bar",
"The Cat & The Dog",
"Light house",
var streets =
["האנגר 28,נמל תל אביב",
"אבן גבירול 30,תל אביב",
"רחוב נמל תל אביב",
"קרליבך 28,תל אביב",
"האנגר 23,נמל תל אביב"]
var images = [UIImage(named: "Shalvata"),
UIImage(named: "Markid"),
UIImage(named: "Litzman Bar"),
UIImage(named: "CatNDog"),
UIImage(named: "LightHouse")]
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
{
return 100.5;
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
////////
////////
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
let cell = self.tableView.dequeueReusableCellWithIdentifier("CustomCell", forIndexPath: indexPath) as! CustomCell
let user = filteredUsers[indexPath.row]
cell.photo.image = user.image
cell.name.text = user.name
cell.streetName.text = user.streetName
return cell
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.performSegueWithIdentifier("BarsProfile", sender: nil)
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if(segue.identifier == "BarsProfile") {
if(segue.destination is DetailView) {
let destVC = segue.destination as! DetailView
// Set variables in Detail View here
// e.g. :
destVC.detailData = selectedData
}
}
}