Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/100.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios PFQueryTableViewController带分区导致分页不起作用_Ios_Objective C_Uitableview_Parse Platform_Parseui - Fatal编程技术网

Ios PFQueryTableViewController带分区导致分页不起作用

Ios PFQueryTableViewController带分区导致分页不起作用,ios,objective-c,uitableview,parse-platform,parseui,Ios,Objective C,Uitableview,Parse Platform,Parseui,我遵循了这个教程 并且能够让我的PFQueryTableView控制器处理分区。标题名称基于行的月份/年份。问题是我并没有得到一个“加载更多”的细胞在我的表结束 这是我认为需要修改的方法… - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { [super tableView:tableView numberOfRowsInSection:section]; NSStr

我遵循了这个教程

并且能够让我的PFQueryTableView控制器处理分区。标题名称基于行的月份/年份。问题是我并没有得到一个“加载更多”的细胞在我的表结束

这是我认为需要修改的方法…

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
[super tableView:tableView numberOfRowsInSection:section];
NSString *sportType = [self sportTypeForSection:section];
NSArray *rowIndecesInSection = [self.sections objectForKey:sportType];
if (section == self.sections.count)
    return rowIndecesInSection.count+1;
else
    return rowIndecesInSection.count;
}
PFQueryTableViewController.m

注意:WOD是PFObject的一个子类

@interface WodLogPFQueryViewController : PFQueryTableViewController
{
    BOOL isSearching;
}
@property (nonatomic, retain) NSMutableDictionary *sections;
@property (nonatomic, retain) NSMutableDictionary *sectionToSportTypeMap;
@end

@implementation WodLogPFQueryViewController
@synthesize sections = _sections;
@synthesize sectionToSportTypeMap = _sectionToSportTypeMap;

- (id)initWithStyle:(UITableViewStyle)style {
    self = [super initWithStyle:style];
    if (self) {

        self.parseClassName = @"WodLog";
        self.pullToRefreshEnabled = YES;
        self.objectsPerPage = 6;
        self.paginationEnabled = YES;
        self.sections = [NSMutableDictionary dictionary];
        self.sectionToSportTypeMap = [NSMutableDictionary dictionary];
    }
    return self;
}

-(PFQuery *)queryForTable {
    PFQuery *query = [WOD query];
    [query whereKey:@"user" equalTo:[PFUser currentUser]];
    [query orderByDescending:@"date"];
    return query;
}

#pragma mark - PFQueryTableViewController

- (NSString *)sportTypeForSection:(NSInteger)section {
    return [self.sectionToSportTypeMap objectForKey:[NSNumber numberWithInt:(int)section]];
}

- (void)objectsDidLoad:(NSError *)error {
    [super objectsDidLoad:error];

    [self.sections removeAllObjects];
    [self.sectionToSportTypeMap removeAllObjects];

    NSInteger section = 0;
    NSInteger rowIndex = 0;
    for (WOD *object in self.objects) {
        NSString *sportType = [object monthYear];
        NSMutableArray *objectsInSection = [self.sections objectForKey:sportType];
        if (!objectsInSection) {
            objectsInSection = [NSMutableArray array];

            // this is the first time we see this sportType - increment the section index
            [self.sectionToSportTypeMap setObject:sportType forKey:[NSNumber numberWithInt:(int)section++]];
        }

        [objectsInSection addObject:[NSNumber numberWithInt:(int)rowIndex++]];
        [self.sections setObject:objectsInSection forKey:sportType];
    }
    [self.tableView reloadData];
}

- (PFObject *)objectAtIndexPath:(NSIndexPath *)indexPath {
    if (self.objects.count != indexPath.row) {
        NSString *sportType = [self sportTypeForSection:indexPath.section];
        NSArray *rowIndecesInSection = [self.sections objectForKey:sportType];
        NSNumber *rowIndex = [rowIndecesInSection objectAtIndex:indexPath.row];
        return [self.objects objectAtIndex:[rowIndex intValue]];
    } else {
        return self.objects[indexPath.row];
    }
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(WOD *)object
{   
    static NSString *identifier = @"WodLogObject";

    WodLogTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
    //cell.backgroundColor = [ColorTools colorFromHexString:@"#1f2124"];

    WOD *wodLog = object;

    if (cell == nil) {
        cell = [[WodLogTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        UIButton *delButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [delButton setBackgroundImage:[UIImage imageNamed:@"wodLogListDel"] forState:UIControlStateNormal];
        delButton.frame = CGRectMake(288, 29, 24, 24);
        cell.editingAccessoryView = delButton;
        [delButton addTarget:self action:@selector(cellDeleteClicked:forEvent:) forControlEvents:UIControlEventTouchUpInside];
    }

    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSArray *weekDays = [NSArray arrayWithObjects:@"SUN", @"MON", @"TUE", @"WED", @"THU", @"FRI", @"SAT", nil];

    NSDateComponents *component = [calendar components:NSWeekdayCalendarUnit|NSDayCalendarUnit fromDate:wodLog.date];

    cell.weekDayLabel.text = [weekDays objectAtIndex:([component weekday] - 1)];
    cell.dateLabel.text = [NSString stringWithFormat:@"%ld", (long)[component day]];
    cell.nameLabel.text = wodLog.name;
    cell.descriptionLabel.text = wodLog.desc;
    [cell setResult:wodLog.result forType:wodLog.type];
    cell.prescribedImageView.hidden = ![wodLog.prescribed boolValue];
    cell.perRecImageView.hidden = ![wodLog.personalrecord boolValue];

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [super tableView:tableView didSelectRowAtIndexPath:indexPath];

    if ((indexPath.row + 1) > [self.objects count]) {
        NSLog(@"Load More... was tapped");
        [self loadNextPage];
        return;
        //rest of didSelectRowAtIndexPath doesn't run because of return;
    }
    PFObject *selectedObject = [self objectAtIndexPath:indexPath];
    NSLog(@"name = %@", selectedObject[@"name"]);
}

#pragma mark - UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.sections.allKeys.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    [super tableView:tableView numberOfRowsInSection:section];
    NSString *sportType = [self sportTypeForSection:section];
    NSArray *rowIndecesInSection = [self.sections objectForKey:sportType];
    if (section == self.sections.count)
        return rowIndecesInSection.count+1;
    else
        return rowIndecesInSection.count;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    NSString *sportType = [self sportTypeForSection:section];
    return sportType;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForNextPageAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"NextPage";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    cell.backgroundColor = [ColorTools colorFromHexString:@"#101113"];

    [cell.textLabel setFont:[UIFont fontWithName:@"HelveticaNeue-Medium" size:18.0f]];
    [[UILabel appearanceWhenContainedIn:[UITableViewCell class], nil]
     setTextColor:[UIColor lightGrayColor]];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.textLabel.text = @"Load more...";

    return cell;
}

@end