ios - If I want to create one of three similar types of cells in cellForRowAtIndexPath, how do I set the "common" properties? -


Say that I have three different cell types that look different but some are present in three areas, so they all come from the same super class, say, animal .

But some animals are very different, and this is where the three different types of cells come in.

I want to introduce the right kind of cell, what kind of animal I am, on which I am working. So I can just check the animal's code, type the property, decode the cell, set it up and return it.

But like the name and height, with all the animals and I want to set it in the center without the code being repeated inside the check of every animal.

By using polymorphism I have declared an example of parents, then create each subclass and set specific properties, then set the general people.

  var cell: cattle animal = animals to animals [index.text] switch cattle. Type {case "cat", "dog": cell = table view. PetTableViewCell case "Lizard" as DequeueReusableCellWithIdentifier ("PetCell", for "IndexPath: IndexPath"): LizardTableViewCell cell.scaleAmount = 7 cell.spikes = true for cell = tableView.dequeueReusableCellWithIdentifier ("LizardCell", ForIndexPath: indexPath) Default: cell = tableView.dequeueReusableCellWithIdentifier "Berdkel", as follows: Indekspeth) for Indekspath Berdtebl Viksel Selkvings = true} Sel.animl Nenam Labelktekst = a Imal.name cell.animalHeightLabel.text = animal.heat Sel.animlsound .text = AnimalSound Return Cell   

But let me know I get an error that within the statements of the case it still thinks that the cells are of type AnimalCell , even after I make them correctly, it is not working.

How do I accomplish something like this?

But I think it is still within the statements of case that gets an error that Cells are AnimalCell

because the reason the compiler only takes care of stable type 's cell , its is not for run-time type as an expression you make a change in the type of object specified in cell Cell Does not change the static type var defined by cell: AnimalCell announcement; The assignment for cell does not change its static type

You can set your property by local variables of the appropriate type, through the variable, and then specify it in the end mobile from:

  switch animal. Type {case "cat", "dog": catOrDog = tableView.dequeueReusableCellWithIdentifier ( "PetCell", forIndexPath: Petibl Viksel cell = CAT Orodog case as "Lizard" Lizard Let = tabular view. DequeueReusableCellWithIdentifier ( "lizard cell" for links to: the envelope, Indekspath) lizard as sly Elaisiaarelmount = 7 Lizard. spikes = true cell = lizard default: Let bird = tabular view. Diisiiuaryueblkelvithaidentifayr ( "Berdkel" Indeedepth to: For Ndekspath) Berdtebl as Viksel bird Menkvings = true cell = Bird}    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -