Parse Pagination loadNextPage 2. Seite wird zweimal geladenIOS

Programmierung für iOS
Guest
 Parse Pagination loadNextPage 2. Seite wird zweimal geladen

Post by Guest »

In meiner Parse-App habe ich die Paginierung aktiviert und zu Testzwecken die Anzahl der Objekte pro Seite auf 5 festgelegt. Wenn ich die App ausführe, wird dies in meiner TableView angezeigt

Code: Select all

1
2
3
4
5
Load More
Nachdem Sie auf „Mehr laden“ geklickt haben, sieht die gesamte Tabelle wie folgt aus:

Code: Select all

1
2
3
4
5
6
7
8
9
10
6
7
8
9
10
Wenn Sie danach auf „Mehr laden“ klicken, wird der Satz von 11-15 zweimal hinzugefügt. Was ist los?

Code: Select all

- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {

// The className to query on
self.parseClassName = @"Prayers";

// Whether the built-in pull-to-refresh is enabled
self.pullToRefreshEnabled = YES;

// Whether the built-in pagination is enabled
self.paginationEnabled = YES;

// The number of objects to show per page
self.objectsPerPage = 5;

}
return self;
}
- (PFQuery *)queryForTable {
PFQuery *query = [PFQuery queryWithClassName:@"Prayers"];

// If no objects are loaded in memory, we look to the cache first to fill the table
// and then subsequently do a query against the network.
if (self.objects.count == 0) {
query.cachePolicy = kPFCachePolicyCacheThenNetwork;
}

[query orderByDescending:@"createdAt"];

return query;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
object:(PFObject *)object
{
static NSString *CellIdentifier = @"Cell";

Cell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[Cell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}

self.theObject = object;
BOOL anony = [object[@"Anonymous"] boolValue];

cell.profileName.text = object[@"Title"];
cell.contentLabel.text = object[@"Request"];
cell.firstName = object[@"FirstName"];
cell.lastName = object[@"LastName"];
cell.iostoken = object[@"DeviceID"];
cell.request = object[@"Title"];
cell.prayerObject = object;
PFFile *thumbnail = object[@"ProfilePic"];
cell.profilePic.image = [UIImage imageNamed:@"[email protected]"];
/*[cell.commentButton addTarget:self action:@selector(didTapCommentButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[cell.commentButton setTitle:@"Share" forState:UIControlStateNormal];
[cell.commentButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[cell.commentButton setTitleColor:[UIColor greenColor] forState:UIControlStateHighlighted];*/
[thumbnail getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) {

UIImage *thumbnailImage = [UIImage imageWithData:imageData];
UIImageView *thumbnailImageView = [[UIImageView alloc] initWithImage:thumbnailImage];

cell.profilePic.image = thumbnailImage;

}];
NSString *dates = object[@"dateMade"];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MMM_dd_yyyy"];
NSDate *datefromstring = [formatter dateFromString:dates];
NSDateFormatter *formatter2 = [[NSDateFormatter alloc] init];
[formatter2 setDateFormat:@"MMM dd, yyyy"];
cell.dateLabel.text = [formatter2 stringFromDate:datefromstring];
UIFont *cellFont = [UIFont fontWithName:@"Verdana-Bold" size:15];
UIFont *cellFont2 = [UIFont fontWithName:@"Verdana-Bold"  size:12];

return cell;
}
- (PFObject *)objectAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == self.objects.count) {
return nil;
} else {
return [super objectAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]];
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

PFObject *object = [self objectAtIndexPath:indexPath];

if (object == nil) {
// Return a fixed height for the extra ("Load more") row
return 70;
} else {

NSLog(@"%lu",  (unsigned long)[self.objects count]);
PFObject *entry = [self.objects objectAtIndex:indexPath.row];
NSString *commentString = entry[@"Request"];
NSString *nameString = @"";
NSLog(@"%@", commentString);
return [Cell heightForCellWithContentString:(NSString *)commentString] +25 ;
}
}
#pragma mark -
#pragma mark Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

[super tableView:tableView didSelectRowAtIndexPath:indexPath];

[tableView deselectRowAtIndexPath:indexPath animated:YES];

if (indexPath.row == self.objects.count && self.paginationEnabled) {
// Load More Cell
NSLog(@"Load More");
[self loadNextPage];
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post