UrbanPro

Learn iOS Developer from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

How do you make a UI TableView have different numbers of rows in different sections?

Asked by Last Modified  

Follow 4
Answer

Please enter your answer

3 down vote accepted You can't use loop like you're doing since that just gives each cell in that section the value in the last index that you loop through (index 2, or 4). Normally, for a sectioned table view, you would use an array of arrays to populate the sections. If you want to use a single...
read more
3 down vote accepted You can't use loop like you're doing since that just gives each cell in that section the value in the last index that you loop through (index 2, or 4). Normally, for a sectioned table view, you would use an array of arrays to populate the sections. If you want to use a single array, and the number of rows in each section stay like you show them, then the following should work, Example:- class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { var titles=["1", "2", "3", "4", "5"] override func viewDidLoad() { super.viewDidLoad() } func numberOfSectionsInTableView(tableView: UITableView) -> Int { return 3 } func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { if section== 0 { return 3 } else if section== 1 { return 1 } else { return 2 } } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let myCell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! UITableViewCell if indexPath.section == 0 { myCell.textLabel!.text = titles[indexPath.row] } else if indexPath.section == 1 { myCell.textLabel!.text = "Section 2" } else { myCell.textLabel!.text = titles[indexPath.row + 3] } return myCell } } read less
Comments

Technical Architect (14+ years in IT, 10+ years in iOS, Polyglot programmer, C/C++,Python,Golang)

check this method: https://developer.apple.com/documentation/uikit/uitableview/ method: Swift numberOfRows(inSection section: Int) -> Int Objective C - (NSInteger)numberOfRowsInSection:(NSInteger)section; Here you can decide based on which section how many rows should be returned.
Comments

Trainer

We can achieve this by implementing the UITableviewDataSource delegate method 'numberofRowsInSection', which gives us a section parameter where we can return the required number of rows for each section. PFB some sample code - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section...
read more
We can achieve this by implementing the UITableviewDataSource delegate method 'numberofRowsInSection', which gives us a section parameter where we can return the required number of rows for each section. PFB some sample code - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { switch (section) { case 0: return 5; case 1: return 4; default: return 1; } } read less
Comments

Tutor

We have Delegate methods numberOFRowsForSection:(NsInteger )Section In This method section is the parameter to which you want to return row count.. suppose for first section (that means as our index start with 0 section value will be 0) you can return 2 rows... In the Above mentioned method you can...
read more
We have Delegate methods numberOFRowsForSection:(NsInteger )Section In This method section is the parameter to which you want to return row count.. suppose for first section (that means as our index start with 0 section value will be 0) you can return 2 rows... In the Above mentioned method you can right a if condition that is section is 0 need to return 3 rows If (section == 0) return 3l read less
Comments

View 2 more Answers

Related Questions

I am interested doing at iOS developer. So, kindly suggest me the best institutes which will improves my knowledge at best and provides me a good placement.
Dear Hemalatha, I don't know, why you are looking for iOS development Training. If it's only for placement, there are so many institutes are available in Hyderabad(Ameerpet). But if you want to create...
Hemalatha
0 0
5
I want to join an IT academy which can provide me 100% guaranteed job. Can you suggest some?
Hi Anuja, There is nothing or no one in the world who can guarantee you a job except your own hard work and will to succeed in life. A good tutor can guide you in the right direction and provide assistance...
Anuja
What is the fees structure of IOS training and what is the time duration?
you will get different answers from different ppl and institutes....i would invite you to a conversation where we can discuss your needs to adapt the duration and thus the fees as well.
Shivangi
0 0
8
How much fees for IOS developer training and its exact training time?
One hour daily, and its cost Rs. 6000 monthly.
Shubham

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Recommended Articles

Almost all of us, inside the pocket, bag or on the table have a mobile phone, out of which 90% of us have a smartphone. The technology is advancing rapidly. When it comes to mobile phones, people today want much more than just making phone calls and playing games on the go. People now want instant access to all their business...

Read full article >

Information technology consultancy or Information technology consulting is a specialized field in which one can set their focus on providing advisory services to business firms on finding ways to use innovations in information technology to further their business and meet the objectives of the business. Not only does...

Read full article >

Whether it was the Internet Era of 90s or the Big Data Era of today, Information Technology (IT) has given birth to several lucrative career options for many. Though there will not be a “significant" increase in demand for IT professionals in 2014 as compared to 2013, a “steady” demand for IT professionals is rest assured...

Read full article >

Hadoop is a framework which has been developed for organizing and analysing big chunks of data for a business. Suppose you have a file larger than your system’s storage capacity and you can’t store it. Hadoop helps in storing bigger files than what could be stored on one particular server. You can therefore store very,...

Read full article >

Looking for iOS Developer Training?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for iOS Developer Classes?

The best tutors for iOS Developer Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn iOS Developer with the Best Tutors

The best Tutors for iOS Developer Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more