0

I have 2 sections which is fixed and 3 rows which is fixed.Each row is loaded by a tableviewcell,which means it has 3 tableviewcell. How to load the cellforrowat for each section with each tableviewcell. The 3 tableview cell for as follows:

tableviewcell1:
 guard let cell = tableView.dequeueReusableCell(withIdentifier: "AreaHeadderTableViewCell") as? AreaHeadderTableViewCell else {return UITableViewCell()}
return cell


tableviewcell2:

guard let cell = tableView.dequeueReusableCell(withIdentifier: "DetailItemTblCell") as? DetailItemTblCell else {return UITableViewCell()}
return cell

tableviewcell3:

 guard let cell = tableView.dequeueReusableCell(withIdentifier: "AreaHeadderTableViewCell") as? AreaHeadderTableViewCell else {return UITableViewCell()}

return cell

How to showcase these 3 tableviewcell for both sections?

1 Answer 1

1

You need to write your cellForRowAt function so it looks at the section number of the cell being requested, and creates and configures the appropriate type of cell based on the request. For a sectioned table view a switch statement might be a good choice for handling that.

I would suggest searching for a tutorial on creating a sectioned table view and going through it. There is a fair amount to learn, and some gotchas. It's more than we can cover in an SO answer.

Sign up to request clarification or add additional context in comments.

2 Comments

is it like inside cellforrow i use switch(indexpath.section):
Yes, exactly. Switch based on the section number, and then create and configure the appropriate type of cell for each case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.