gpt4 book ai didi

ios - 将 TableView Controller 更改为 View Controller

转载 作者:行者123 更新时间:2023-12-01 18:19:21 25 4
gpt4 key购买 nike

我有一个使用 JSON 显示信息的 TableView Controller 。我想更改我的应用程序的样式,并且我不希望它具有现在的“表格” View 。将我的 Table View Controller 更改为常规 View Controller 的最简单方法是什么,我遇到的最大问题是代码使用 tableView 而我不知道如何让它作为常规 View Controller 工作。

我使用了一个带有 TableViewController 的 Storyboard,它链接到一个名为 UpcomingReleasesViewController 的 Controller 。

我想要我的应用程序:
https://www.dropbox.com/s/ehs2vpsv3671s2j/Photo%20Sep%2003%2C%203%2015%2042%20PM.png

看起来像这样:
https://www.dropbox.com/s/q5yfhrs4fr8uvvm/Photo%20Aug%2029%2C%201%2011%2035%20AM.png

最佳答案

我最初的答案是假设您只想从 UITableViewController 转换到 UIViewController .查看您的屏幕快照,我推断您确实想从 UITableViewController 切换到 UICollectionViewController (这是 iOS 6 的一项功能,可让您精确地做您想做的事)。

在这种情况下,将您的基类更改为 UICollectionViewController , 并替换您的 UITableViewDataSource UICollectionViewDataSource 的方法方法。然后使用 Collection View Controller 重新设计您的场景。

Collection View Programming Guide了解更多信息。或查看 WWDC 2012 session Introducing Collection ViewsAdvanced Collection Views and Building Custom Layouts .

如果您需要支持 6 之前的 iOS 版本,那么您必须自己手动编写此 Collection View 样式编码,将您的 ImageView 放在 ScrollView 上并使用标准 UIViewController .它比使用 Collection View 需要更多的努力,但可以做到。

原答案:

如果这个 View Controller 上面会有一个表格 View ,但你只是想在场景中添加更多的控件?如果是这样,只需将 View Controller 的基类从 UITableViewController 更改为至UIViewController ,创建新场景,向其中添加表格 View ,并将表格 View 的委托(delegate)和数据源指定为 View Controller :

enter image description here

另外,请确保您定义了 IBOutlet对于您的表格 View (如果您将其称为 tableView ,这将最大限度地减少所需的任何编码更改)。

enter image description here

如果这样做,您可以快速转换 UITableViewController基于 Controller 到 UIViewController以最少的代码更改。

关于ios - 将 TableView Controller 更改为 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18599538/

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