测试已测试 | ✗ |
Lang语言 | Obj-CObjective C |
许可证 | MIT |
发布最新版本 | 2014年12月 |
由 Oliver Letterer 维护。
SLRESTfulCoreDataUI 是 SLRESTfulCoreData 的 UI 扩展,目前具有创建和编辑由 SLRESTfulCoreData 支持的实体。
pod 'SLRESTfulCoreDataUI', '~> 1.0'
SLEntityViewController 是 UITableViewController 的子类,用于管理和创建或编辑 NSManagedObject 实体。
让我们以下面示例实体作为参考
@interface SLEntity1 : NSManagedObject
@property (nonatomic, strong) NSNumber *dummyBool;
@property (nonatomic, strong) NSNumber *booleanValue;
@property (nonatomic, strong) NSString *stringValue;
@property (nonatomic, strong) NSDate *dateValue;
@property (nonatomic, strong) SLEntity2 *toOneRelation;
@property (nonatomic, strong) NSSet *toManyRelation;
@end
要设置和配置 SLEntityViewController
SLEntityViewController *viewController = [[SLEntityViewController alloc] initWithEntity:self.entity editingType:SLEntityViewControllerEditingTypeCreate];
/*
setup property mapping, keys are the attributes of the entity
and values their human readable representation which will be displayed to to user
*/
viewController.propertyMapping = @{
@"booleanValue": NSLocalizedString(@"BOOL", @""),
@"stringValue": NSLocalizedString(@"String", @""),
@"dateValue": NSLocalizedString(@"Date", @""),
@"dummyBool": NSLocalizedString(@"dummy", @""),
};
// setup completion handler
[self.viewController setCompletionHandler:^(BOOL didSaveEntity) {
// called when done, dismiss view controller here
}];
要现在显示任何数据给用户,SLEntityViewController 从 SLEntityViewController.sections
接收一个包含区域的数组
@interface SLEntityViewControllerSection : NSObject <NSCopying>
// a static section which displays basic properties of the entity. These can belong to attributes or relationships.
+ (instancetype)staticSectionWithProperties:(NSArray *)properties;
// let the user choose an option from a finite set of values.
// enumValues will applied to your entity and humanReadableOptions will be displayed to the user for selection.
+ (instancetype)staticSectionWithEnumValue:(NSArray *)enumValues humanReadableOptions:(NSArray *)humanReadableOptions forAttribute:(NSString *)attribute;
// Let the user choose entites for to-one or to-many relationships based on the specified fetchedResultsController.
+ (instancetype)dynamicSectionWithRelationship:(NSString *)relationship
fetchedResultsController:(NSFetchedResultsController *)fetchedResultsController
formatBlock:(NSString *(^)(id entity))formatBlock;
@end
Oliver Letterer
SPLWindow 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。