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

Which is the best centre or person or institute to study iOS application development in Bangalore....
We conduct online trainings in iOS. Note however that you need to have a Mac to learn iOS App Development.
Geeyar
0 0
8
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
I want to be a web/ios/android developer though I have studied till class10. So can I do the course to work as a freelancer? M y main query is I have heard about many things which we get to study when we do B.Sc but I am not up to that level so can I do the course?
Hi Ashutosh , I like your confidence and would like to say definitively you can do the course , as you are upto 10 th class so it may be very difficult to get jobs in companies but if you will have good...
Ashutosh
Hello, I am new in iOS development. What is the best way of learning iOS and Programming also?
You could start learning objective C for iOS app development. Please contact us for more information.
Vikas
What courses can I do to become an iOS app developer specializing in games?
Hi Rajeev, You can take two approaches : 1) Learn the native iOS Game Development Framework. It is called SpriteKit. For 3D games, you have SceneKit and Metal. If you already have iOS App development...
Rajeev J
0 0
6

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

Ask a Question

Related Lessons

Learning Path For Mobile Application Development
I. Traditional Approach: 1. Native Android Application Development: Android is a mobile operating system that runs on phones, tablets, smartwatches, TVs and more. You can learn Android Application Development...

10 Ways My Life Changed When I Learned To Code
1. I have freedom to make my own schedule. 2. I earn more, but work fewer hours. 3. I can say “no” to job offers. 4. People come to me asking if I can work for them. 5. I never have to...

MapKit Tutorial with Swift in iOS 8
Using Map Kit, the portion of the map that is displayed on the screen is referred to as the region. The region is defined by a center location and a span of the surrounding area to be displayed. Inside...

IOS App Development
Student could work on the normal laptop or system. Some of student are thinking that Mac operating system is mandatory for Learn IOS but this is not mandatory. Thanks Ajay

Developing iOS Apps Part 1
The Basics Swift opts to use a Javascript-like ‘var’ keyword to define any new variable. So for example to create a new variable with a bit of text in it, you would have this: var...

P Balasubramanyam

0 0
0

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