我下面这个论坛:https://parse.com/questions/using-pfquerytableviewcontroller-for-uitableview-sectionsPFQueryTableViewController多路段
如果你去上面的链接和阅读题,你会看到,我想在我PFQueryTableViewController
缔造出款款。复制上面的链接的代码形式后,我能够切断我的TableView就好了..它工作的很棒!这是我的问题。 (做这件事的最好方法就是举一个例子)。想象我有2个细胞的细胞3段中的每个部
甲 乙
Ç d
Ë ˚F
当我点击A I得到的一个结果。当我点击B时,我得到B结果。 但是当我点击CI得到A,并且当我点击DI获得B.当我点击EI获得A并且当我点击FI获得B.
基本上它知道有部分,但它是使得它好像有1个部分连续重复(3)次。
这里是捕捉。 TableView中的单元显示正确的信息。它是在您点击传输错误信息的单元格之后。也许我错过了一些东西,但我不知道在哪里。
这里是我的代码:
@property (nonatomic, retain) NSMutableDictionary *sections;
@property (nonatomic, retain) NSMutableDictionary *sectionToSportTypeMap;
@implementation AllDataViewController
@synthesize sections = _sections;
@synthesize sectionToSportTypeMap = _sectionToSportTypeMap;
- (id)initWithCoder:(NSCoder *)aCoder
{
self = [super initWithCoder:aCoder];
if (self) {
// Custom the table
// The className to query on
self.parseClassName = @"schedule";
self.textKey = @"name";
self.pullToRefreshEnabled = YES;
self.paginationEnabled = YES;
self.objectsPerPage = 25;
self.sections = [NSMutableDictionary dictionary];
self.sectionToSportTypeMap = [NSMutableDictionary dictionary];
}
return self;
}
- (PFQuery *)queryForTable
{
PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];
// If Pull To Refresh is enabled, query against the network by default.
if (self.pullToRefreshEnabled) {
query.cachePolicy = kPFCachePolicyNetworkOnly;
}
// 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 orderByAscending:@"order"];
return query;
}
- (void) objectsDidLoad:(NSError *)error
{
[super objectsDidLoad:error];
[self.sections removeAllObjects];
[self.sectionToSportTypeMap removeAllObjects];
NSInteger section = 0;
NSInteger rowIndex = 0;
for (PFObject *object in self.objects) {
NSString *sportType = [object objectForKey:@"order"];
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:section++]];
}
[objectsInSection addObject:[NSNumber numberWithInt:rowIndex++]];
[self.sections setObject:objectsInSection forKey:sportType];
}
}
- (PFObject *)objectAtIndexPath:(NSIndexPath *)indexPath {
NSString *sportType = [self sportTypeForSection:indexPath.section];
NSArray *rowIndecesInSection = [self.sections objectForKey:sportType];
NSNumber *rowIndex = [rowIndecesInSection objectAtIndex:indexPath.row];
return [self.objects objectAtIndex:[rowIndex intValue]];
}
#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return self.sections.allKeys.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSString *sportType = [self sportTypeForSection:section];
NSArray *rowIndecesInSection = [self.sections objectForKey:sportType];
return rowIndecesInSection.count;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
NSString *sportType = [self sportTypeForSection:section];
return sportType;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[super tableView:tableView didSelectRowAtIndexPath:indexPath];
PFObject *selectedObject = [self objectAtIndexPath:indexPath];
}
- (NSString *)sportTypeForSection:(NSInteger)section {
return [self.sectionToSportTypeMap objectForKey:[NSNumber numberWithInt:section]];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"showDataDetail"]) { //showRecipeDetail
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
//PFObject *selectedObject = [self objectAtIndexPath:indexPath];
DataDetailViewController *destViewController = segue.destinationViewController;
PFObject *object = [self.objects objectAtIndex:indexPath.row];
AllData *data = [[AllData alloc] init];
data.title = [object objectForKey:@"title"];
data.imageFile = [object objectForKey:@"imageFile"];
data.date = [object objectForKey:@"date"];
data.information = [object objectForKey:@"information"];
destViewController.data = data;
}
}
加法:我敢肯定它与'prepareForSegue'做,因为当我登录''didSelectRowAtIndexPath方法我获得正确的信息。 – Nicholas 2014-09-29 02:43:53
授予我没有通读所有的代码,但如果它发生在'prepareForSegue'中,并且您有多个部分,但您只是继续阅读第一部分中的信息,可能是因为这一行:'PFObject * object = [self.objects objectAtIndex:indexPath.row];'从'objects'数组中抓取的对象完全依赖于行而不考虑该部分。因此,如果选择第2节中的第1行,假设您的数据是按照标准顺序排列的,则您仍然会继续执行第1节中的第1行。 – 2014-09-29 02:48:20
我有更多的写作比适合评论,所以我会提供一个正确的答案...如果我在错误的轨道上,请随时让我知道。 – 2014-09-29 02:54:13