问题描述
我在做什么?
我正在通过构建应用来学习 iOS
。我的要求显示了 UITableViewController上的一些交易
What am I doing?
I am learning iOS
by building an app. My requirement shows some transactions on UITableViewController
我需要添加标题
我需要设计一些具体的信息和风格。我问过并意识到我需要制作一个自定义 UIView
。
I need to add header
which I need to design with some specific information and style. I asked iOS: How do I make custom header section for Table? and realized that I need to make a custom UIView
.
问题是我无法在 UITableViewController 查看
c>,XCode不允许我
Problem is that I can't drag View
on UITableViewController
, XCode does not allow me to
问题?
- 如果你看到这不仅显示 UIView
但是整个 iPhone
屏幕
- 我需要在我的 UITableViewController上显示这个
,现在我拥有什么,如何将 UIView
作为标题放在我的 UITableViewController
上?
Problem?
- If you see this shows not only the UIView
but the entire iPhone
screen
- I need to show this on my UITableViewController
, with now what I have, how can I put the UIView
as header on my UITableViewController
?
推荐答案
使用 UIViewController
而不是a UITableViewController
Use a UIViewController
rather than a UITableViewController
我建议你不要使用 UITableViewController
因为我可以看到它没有什么优势,而像你正在寻找的自定义视图是不必要的困难。
I recommend you don't use a UITableViewController
as there's little advantage as far as I can see, whilst custom views like you're looking for are unnecessarily difficult.
使用的 UIViewCont滚动
并将 UITableView
对象(在界面构建器中)拉到该视图。您可以根据自己的喜好调整尺寸和位置。
Use a UIViewController
and pull a UITableView
object (Within the interface builder) on to that view. You can size and position it anywhere you like.
请记住在头文件中包含代理,如下所示,并将 UITableView
对象委托连接到viewController。
Remember to include the delegates within the header file, like below, and to connect the UITableView
object delegate to the the viewController.
@interface ViewController: UIViewController<UITableViewDelegate, UITableViewDatasource>
下面是界面构建器中UIViewController的屏幕截图,我添加了一个UITableview对象(灰色在这里)并在顶部添加了一个UIView(颜色为棕色,因此你可以清楚地看到它)。
Screenshot below of a UIViewController within the interface builder and I've added a UITableview object (which is greyed out here) and added a UIView at the top (coloured brown so you can see it clearly).
这当然只是一个例子,但希望它可以帮助你获得想法。
This of course is just an example, but hope it helps you get the idea.
虽然在上面的屏幕截图中我使用的是故事板,但你也可以使用Xib来做同样的事情。
Although in the above screen shot I'm using storyboard, though you can do this just the same with a Xib too.
我希望这会有所帮助。
这篇关于iOS:无法在UITableViewController上创建自定义视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!