---
title: "How to set different section titles in UITableView in Objective-C?"  
description: "How to set different section titles in UITableView in Objective-C?"  
author: "Anonymous User"  
published: 2016-02-28  
updated: 2016-02-29  
canonical: https://www.mindstick.com/forum/34016/how-to-set-different-section-titles-in-uitableview-in-objective-c  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 1 minute  

---

# How to set different section titles in UITableView in Objective-C?

I have created an Contact [application](https://www.mindstick.com/articles/12824/calculator-application-in-android) and displaying it into the *UITableVIew*. I want to display the contact names in different sections with different [section](https://yourviews.mindstick.com/view/297/reservation-for-economically-weaker-section) titles.\
currently I am using *numberOfSectionsInTableView*: the [table](https://www.mindstick.com/articles/43918/how-to-design-table-using-bootstrap) [view delegate](https://www.mindstick.com/forum/33747/how-to-create-view-delegate-in-ios) [method](https://www.mindstick.com/forum/166/webservice-method) for managing sections, like this:

```
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{    return 1;}
```

but as you can see that currently I am [returning](https://www.mindstick.com/news/2477/returning-ceo-bob-iger-dismisses-the-disney-apple-sale-as-pure-speculation) 1 which is creating only one section. My main [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) is to display different section titles, So can you tell me that how can we set the section headers without repeating titles?

## Replies

### Reply by Tarun Kumar

UITableView provides a [delegate](https://www.mindstick.com/articles/777/delegate-and-event-in-c-sharp) method titleForHeaderInSection: for setting the section titles.\
Here is an example: we have an array of sectionTitles:\
*NSArray *sectionTitles = [[NSArray alloc] initWithObjects:@"A",@"B",@"C",@"D",@"E",@"F",@"G",nil];*\
now return the total no of sections in the numberOfSectionsInTableView: method, like this:

```
-(NSInteger)numberOfSectionsInTableView:(UITableView *)searchBar{  return [sectionTitles count];}
```

and return the section titles in titleForHeaderInSection: method, like this:

```
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{  return [sectionTitles objectAtIndex:section];}
```

above method is responsible for putting the titles of sections using the *sectionTitles* array.


---

Original Source: https://www.mindstick.com/forum/34016/how-to-set-different-section-titles-in-uitableview-in-objective-c

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
