测试已测试 | ✗ |
语言语言 | Obj-CObjective C |
许可证 | MIT |
发布最新发布 | 2014年12月 |
由Michael Avila维护。
要运行示例项目
hub clone michaelavila/UITableViewDataSource-RACExtensions
,如果您尚未做的话cd UITableViewDataSource-RACExtensions
cd Examples/Basic
或者 cd Examples/Custom
prepareToAppear
bundle install
,如果您没有bundler,则首先运行 gem install bundler
bundler exec pod install
打开 Example.xcworkspace
Basic 和 Protocol 示例之间的主要区别在于 RACTableViewCell 协议的使用,用于渲染除了字符串之外的对象。
这两个示例都很短,应该很容易理解。特别是,注意两个项目中的 EAppDelegate.m
文件。在 Protocol 项目中,重要的是要注意额外的 ETableViewCell
类以及 Main.storyboard
中原型单元格上的那个类。注意它们。
如果您 #import <UITableViewDataSource-RACExtensions/UITableViewController+RACTableViewDataSource.h>
,那么所有的UITableViewControllers都将有 rac_dataSource
方法。dataSource 的签名如下所示
- (id<UITableViewDataSource>)rac_dataSource:(RACSignal *)signal reuseIdentifier:(NSString *)reuseIdentifier;
由 signal
发出的事件将被绑定到 UITableView 的数据。reuseIdentifier
指定在您想要从中创建新细胞视图的 UITableViewCell 上。
以下是基本使用以及更复杂数据的示例。首先是基本的示例
#import "EAppDelegate.h"
#import <UITableViewDataSource-RACExtensions/UITableViewController+RACTableViewDataSource.h>
@implementation EAppDelegate
{
id<UITableViewDataSource> groceryList;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
groceryList = [(UITableViewController *)self.window.rootViewController
rac_dataSource:[RACSignal return:@[@"Bananas", @"Beer"]]
reuseIdentifier:@"groceryListItemCell"];
return YES;
}
@end
然后是更复杂数据的示例
#import "EAppDelegate.h"
#import <UITableViewDataSource-RACExtensions/UITableViewController+RACTableViewDataSource.h>
@implementation EAppDelegate
{
id<UITableViewDataSource> groceryList;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
groceryList = [(UITableViewController *)self.window.rootViewController
rac_dataSource:[RACSignal return:@[
@{@"name": @"Oranges", @"quantity": @"2 dozen"},
@{@"name": @"Beer", @"quantity": @"6 pack"}
]]
reuseIdentifier:@"groceryListItemCell"];
return YES;
}
@end
由于dataSource是一个signal,您可以将其替换为更复杂的实际发出网络请求(或不)的signal。
此协议定义了一个简单的方法
- (void)prepareToAppear:(NSObject *)data;
这是 RACTableViewDataSource 使用它为每个单元格提供数据的方法。
有关示例实现,请查看 Protocol 示例中的 ETableViewCell.h
和 ETableViewCell.m
,它从 GitHub 上的 ETableViewCell.h 及其他渲染比 NSString
更复杂的数据的示例。
Michael Avila
Colen Eberhardt的笔记在这里曾受到启发。
UITableViewDataSource-RACExtensions遵循MIT许可证。有关更多信息,请参阅LICENSE文件。