Answer the question
In order to leave comments, you need to log in
iOS breakout tables?
Good day. The question is the following:
I receive a list of ads from the server (20 each), each ad has a distance in kilometers from the user, the list is sorted by increasing distance. I want to make a table with sections "Up to 3 km", "Up to 15 km" and more than 15 km.
How to make a mechanism for loading / loading data into a table with sections?
Here is such an entry (ignore the if (i==0) this is not a valid condition,
NSMutableArray* newPaths = [NSMutableArray array];
for (int i = (int)[self.petsArray count] - (int)[pets count]; i < [self.petsArray count]; i++) {
if (i == 0)
{
[newPaths addObject:[NSIndexPath indexPathForRow:i inSection:0]];
}
else
{
[newPaths addObject:[NSIndexPath indexPathForRow:i inSection:1]];
}
}
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:newPaths withRowAnimation:UITableViewRowAnimationTop];
[self.tableView endUpdates];
Answer the question
In order to leave comments, you need to log in
Get 3 arrays for declarations for 1 section, for the 2nd and for the 3rd.
Add the following methods
- (NSInteger)numberOfSections {
int count = 0;
if (firstSectionArray.count) count++;
if (secondSectionArray.count) count++;
if (thirdSectionArray.count) count++;
return count;
}
- (NSInteger)numberOfRowsInSection:(NSInteger)section {
switch (section) {
case 0: return firstSectionArray.count; break;
case 1: return secondSectionArray.count; break;
case 2: return thirdSectionArray.count; break;
}
return 0;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question