简体   繁体   English

使用情节提要的普通View Controller中的Table View?

[英]Table View inside of a normal View Controller using storyboards?

Is there a way to display a table view inside a normal view controller? 有没有一种方法可以在普通视图控制器中显示表格视图? Whenever I try to add cells to the table view inside of the normal view controller, nothing appears. 每当我尝试将单元格添加到普通视图控制器内部的表视图中时,都不会显示任何内容。 I read somewhere that you could link a table view controller to a table view in a view controller, but I can't figure out how to do that using storyboards. 我在某处读到可以将表视图控制器链接到视图控制器中的表视图的地方,但我不知道如何使用情节提要板来做到这一点。

在此处输入图片说明

Did you create an IBOutlet for your table view? 您是否为表格视图创建了IBOutlet? And is it connected? 并连接吗?

After that's done you need to connected the table view's data source and delegate to the view controller. 完成之后,您需要连接表视图的数据源并将其委托给视图控制器。

https://i.imgur.com/Om1Ego4.gif https://i.imgur.com/Om1Ego4.gif

If you want to add TableView inside normal view without using xib : - add tableview inside view controller. 如果要在不使用xib的情况下在普通视图中添加TableView:-在视图控制器内部添加tableview。 - place tableview cell inside tableview and don't forget to set cell's reuse identifier which will be used in tableview's cellForRowAt method. -将tableview单元格放在tableview内,不要忘记设置将在tableview的cellForRowAt方法中使用的单元格重用标识符。 - add outlets of tableview in your .swift file - set delegate and datasource for tableview in storyboard or you can set inside .swift file as yourtableviewname.delegate = self and yourtableviewname.datasource = self - use tableview's delegate and datasource methods to handle tableview. -在.swift文件中添加tableview的出口-在情节提要中设置tableview的委托和数据源,或者可以在.swift文件中设置为yourtableviewname.delegate = self和yourtableviewname.datasource = self-使用tableview的委托和数据源方法来处理tableview。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Storyboard呈现视图控制器 - Present view controller using Storyboards 使用情节提要板手动启动视图控制器。 - manually start a view controller using storyboards. 使用 Storyboards 以编程方式设置初始视图控制器 - Programmatically set the initial view controller using Storyboards 情节提要中的新视图控制器中未调用表视图委托方法 - table view delegate methods not being called in new view controller in storyboards 在普通视图控制器中创建和填充表视图 - Creating and populating table view in normal view controller 使用图像作为背景与情节提要的静态表格视图 - Using image as background for static table view with storyboards 在导航控制器内部重用视图,并使用情节提要作为模式弹出窗口 - Reusing view inside navigation controller and as a modal popup with storyboards 在故事板上重新排列View Controller场景 - Reordering View Controller Scenes in Storyboards 使用情节提要板将数据从第一模式视图控制器传递到第二模式视图控制器 - Passing data from first to second modal view controller using storyboards 如何使用故事板将两个UINavigationControllers指向一个视图控制器? - How to point two UINavigationControllers to one view controller using storyboards?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM