Reputation: 357
I parse an array into my TableView via JSON but I only want to make my table view show the first 18 things in this array. The array consists 72 objects and gets refreshed every day.
The objects in this array are named "0" - "71"...that doesn't change just the items assigned to them change.
How do I make my array now show only the first 18 of it?
I tried this but no success.
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.arrayNeuheiten.count;
if (arrayNeuheiten <= 17) {
return self.arrayNeuheiten.count;
} else if (arrayNeuheiten > 17 )
return nil;
}
Would be great if anyone could help me with that!
Upvotes: 1
Views: 71
Reputation: 9913
Use this :
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(arrayNeuheiten.count >17)
{
NSRange r;
r.location = 17;
r.length = [someArray count]-17;
[arrayNeuheiten removeObjectsInRange:r];
}
return self.arrayNeuheiten.count;
}
Upvotes: 0
Reputation: 489
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return MIN(18, self.arrayNeuheiten.count);;
}
Upvotes: 1
Reputation: 8460
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return (self.arrayNeuheiten.count<17)?self.arrayNeuheiten.count :17;
}
Upvotes: 0