In my application i display item’s. My JSON feed contains 50 items but first i want to display 25 and when a user scrolls down to the last row it need to load more items.
i’m doing:
Downloading the JSON feed;
NSString *jsonString = [NSString
stringWithContentsOfURL:[NSURL URLWithString:xmlDataUrl]
encoding:NSStringEncodingConversionAllowLossy
error:nil];
SBJSON *parser = [[SBJSON alloc] init];
NSDictionary *results = [parser objectWithString:jsonString error:nil];
parser = nil;
[self setTableData:[results objectForKey:@"feed"]];
//
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
//
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
//return [tableData count];
return 25;
}
And detect last row:
if(indexPath.row == [self.tableData count] - 1)
{
NSLog(@"Last Row");
}
But it’s not detecting the last row. Is this because the JSON it’s downloading contains more than 25 rows?
And how i can add a new row is something like [self.tableDate count] +1; possible?
If i do return [tableData count]; it’s detecting the last row but the rows are already filled for 100% i need to display 25/50 and than +1
Where are you calling that second block of code? Is it in your table delegate’s willDisplayCell: method?
In one of my projects, I have very similar code
With an extra row appended after the ones created for self.search, so in my case I’m checking for self.search.count, but you probably want to look at self.search.count-1