serge2487
serge2487

Reputation: 441

how to insert section into table view?

I have a table view that contains 120 numbers. I was wondering if it is possible to add a section in my tableview after every 12 numbers. This would be easier than having 10 separate arrays of 12 numbers and adding each array to a different section. thanks!

Upvotes: 0

Views: 576

Answers (1)

Scott Forbes
Scott Forbes

Reputation: 7417

I'm reading your question and wondering if I'm missing something here, but: Yes, it's possible.

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 12;
}

...and then in your tableView:cellForRowAtIndexPath: method, use indexPath.section * 12 + indexPath.row as the index into your 120-number array.

Upvotes: 1

Related Questions