我有一个UITableView与交替着色的UITableViewCells.并且可以编辑表:可以重新排序和删除行.当行被重新排序或删除时,如何更新交替背景颜色的单元格?
我正在用它绘制交替的彩色单元格:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if ([indexPath row] % 2) {
// even row
cell.backgroundColor = evenColor;
} else {
// odd row
cell.backgroundColor = oddColor;
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当重新排序或删除行时,不会调用此方法.我不能[tableView reloadData]从以下方法调用,因为它在无限循环中崩溃应用程序:
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
// Move the object in the array
id object = [[self.list objectAtIndex:[fromIndexPath row]] retain];
[self.list removeObjectAtIndex:[fromIndexPath row]];
[self.list insertObject:object atIndex:[toIndexPath row]];
[object release];
// Update the table ???
[tableView reloadData]; // Crashes the app in …Run Code Online (Sandbox Code Playgroud) 我在使用RestKit和CoreData时遇到了一些困难,特别是因为RestKit 0.20的示例和文档很少.
我有一个(托管)对象Song与多对一关系Album.以下代码可以发布JSON,但不能以服务器排除的展平格式发布.
// Defined elsewhere
Album *theAlbum;
RKObjectManager *objMan = [self objectManager];
// Response Mapping
RKObjectMapping *responseMapping = [RKObjectMapping mappingForClass:[Song class]];
[responseMapping addAttributeMappingsFromDictionary:@{ @"song": @"songID" }];
NSIndexSet *statusCodes = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful);
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:responseMapping
pathPattern:@"/api/song"
keyPath:nil
statusCodes:statusCodes];
// Request Mapping
RKObjectMapping *requestMapping = [RKObjectMapping requestMapping];
RKEntityMapping *albumRelationshipMapping = [RKEntityMapping mappingForEntityForName:@"Album" inManagedObjectStore:[objMan managedObjectStore]];
[albumRelationshipMapping addAttributeMappingsFromDictionary:@{@"id": @"albumID", }];
[requestMapping addAttributeMappingsFromDictionary:@{ @"title": @"title", @"length": @"length" }];
[requestMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"album"
toKeyPath:@"album"
withMapping:albumRelationshipMapping]];
requestMapping = [requestMapping inverseMapping]; …Run Code Online (Sandbox Code Playgroud)