Edgar
Edgar

Reputation: 931

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).

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?

enter image description here

Upvotes: 1

Views: 68

Answers (2)

Giau Huynh
Giau Huynh

Reputation: 2148

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. 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).

Upvotes: 1

AdamPro13
AdamPro13

Reputation: 7400

It looks like you will want to use a UITableView and subclass UITableViewCell that defines all the common subviews.

Upvotes: 2

Related Questions