简体   繁体   English

类似的对象 - 不同的内容(objective-c)

[英]Similar objects - different contents (objective-c)

I am newbie. 我是新手。 Trying to make an app where ViewController will have a lot of similar objects vertically but with different contents in it (heading, image and button). 试图创建一个应用程序,其中ViewController将垂直拥有许多类似的对象,但其中包含不同的内容(标题,图像和按钮)。

How to implement this correctly? 如何正确实现? I assume that the block/object which I want to have the same properties (height, length, button alignment...) all the time , should be declared as a class, and after it should be initialized with different objects (images, buttons, headings). 我假设我想要具有相同属性(高度,长度,按钮对齐...)的块/对象应该被声明为一个类,并且应该在它之后用不同的对象(图像,按钮)初始化,标题)。 Am I right? 我对吗?

在此输入图像描述

看起来您将需要使用UITableView和子类UITableViewCell来定义所有常见的子视图。

class VerticalViewController: UIViewController {
    var headerTitle: String
    var buttonTitle: String
    var headerImage: UIImage

    init(headerTitle: String, buttonTitle: String, headerImage: UIImage) {
        self.headerTitle = headerTitle
        self.buttonTitle = buttonTitle
        self.headerImage = headerImage
        super.init()
    }

    required init(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

I'm so sorry, you misunderstood me, I originaly show xample code about VerticalViewController, as your comment, I think your want me show all project, it costs a lot of affort. 我很抱歉,你误解了我,我最初显示关于VerticalViewController的xample代码,作为你的评论,我想你想要我展示所有的项目,它需要花费很多的努力。 OK, Instead of doing that I will show your necessary steps to research to complete this task. 好的,我将展示您完成此任务的必要步骤,而不是这样做。 1. Custom Table View 2. Auto Layout (basic OK). 1.自定义表格视图2.自动布局(基本确定)。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM