BaseKit 是一组iOS类,可以使您的生活更轻松。
您有两种方法可以做到这一点
将代码目录添加到 Code/* 中或选择您需要的库。
使用 BaseKit 创建 iPhone 和 iPad iOS 表单
类似于 Restkit 的UITableView Dynamic cell映射
在后台执行操作。
[BKOperationHelper performBlockInBackground:^{
// Do your operation in background
} completion:^{
// Update UI in main queue
}];
迭代。
[BKIteratingHelper iterateTil:4 usingBlock:^(int number) {
NSLog(@"%d", number);
}];
使用方块显示模态视图控制器。
[self presentModalViewControllerWithBlock:^UIViewController *{
return [[[AnyViewController alloc] init] autorelease];
} animated:YES];
使用方块推送视图控制器。
[self.navigationController pushViewControllerWithBlock:^UIViewController *{
return [[[AnyViewController alloc] init] autorelease];
} animated:YES];
self.tableModel = [BKTableModel tableModelForTableView:self.tableView];
self.tableView.dataSource = self.tableModel;
self.tableView.delegate = self.tableModel;
[BKCellMapping mappingForObjectClass:[Item class] block:^(BKCellMapping *cellMapping) {
[cellMapping mapKeyPath:@"title" toAttribute:@"textLabel.text"];
[cellMapping onSelectRowWithBlock:^(UITableViewCell *cell, Item *item, NSIndexPath *indexPath) {
// Do something
}];
[cellMapping mapObjectToCellClass:[UITableViewCell class]];
[self.tableModel registerMapping:cellMapping];
}];
NSArray *items = [NSArray arrayWithObjects:
[Item itemWithTitle:@"Simple mapping"],
[Item itemWithTitle:@"Nib cell example"],
nil];
[self.tableModel loadTableItems:items];
查看更多 示例请打开 Examples/CellMappingExample/CellMappingExample.xcodeproj项目。
非常容易地使用模型创建连接的表单。每次您添加 "mapAttribute" 时,您必须给出一个属于您的对象的属性名,在值改变后,它将自动保存到属性中。
BaseKit 使用名为 ActionSheetPicker 的外部库,但不幸的是,该库还不支持 ARC,因此您需要在将库导入项目时添加 "-fno-objc-arc"。
self.formModel = [BKFormModel formTableModelForTableView:self.tableView navigationController:self.navigationController];
[BKFormMapping mappingForClass:[Movie class] block:^(BKFormMapping *formMapping) {
[formMapping sectiontTitle:@"Information section" identifier:@"info"];
[formMapping mapAttribute:@"title" title:@"Title" type:BKFormAttributeMappingTypeText];
[formMapping mapAttribute:@"releaseDate" title:@"ReleaseDate" type:BKFormAttributeMappingTypeDatePicker];
[formMapping mapAttribute:@"suitAllAges" title:@"All ages" type:BKFormAttributeMappingTypeBoolean];
[formMapping mapAttribute:@"shortName" title:@"ShortName" type:BKFormAttributeMappingTypeLabel];
[formMapping mapAttribute:@"numberOfActor" title:@"Number of actor" type:BKFormAttributeMappingTypeInteger];
[formMapping mapAttribute:@"content" title:@"Content" type:BKFormAttributeMappingTypeBigText];
[formMapping mapAttribute:@"choice" title:@"Choices" selectValuesBlock:^NSArray *(id value, id object, NSInteger *selectedValueIndex){
*selectedValueIndex = 1;
return [NSArray arrayWithObjects:@"choice1", @"choice2", nil];
} valueWithBlock:^id(id value, id object, NSInteger selectedValueIndex) {
return value;
}];
[formMapping buttonSave:@"Save" handler:^{
}];
[self.formModel registerMapping:formMapping];
}];
[self.formModel loadFieldsWithObject:movie];
查看更多 示例请打开 Examples/FormMappingExample/FormMappingExample.xcodeproj项目。
易于使用的 CoreLocation 管理器,支持方块或默认代理。
BKLocationManager *manager = [BKLocationManager sharedManager];
[manager setDidUpdateLocationBlock:^(CLLocationManager *manager, CLLocation *newLocation, CLLocation *oldLocation) {
NSLog(@"didUpdateLocation");
}];
[manager setDidFailBlock:^(CLLocationManager *manager, NSError *error) {
NSLog(@"didFailUpdateLocation");
}];
[manager startUpdatingLocationWithAccuracy:kCLLocationAccuracyHundredMeters];
BaseKit 完全与 ARC 和非 ARC 项目兼容。
2012/05/17 (0.2.3)
2012/05/12 (0.2)
2012/01/29 (0.1)
如果您使用 BaseKit,我很乐意在这里添加您的应用程序名称。
布鲁诺·威尔蒙特