SimpleTableView 1.0.3

SimpleTableView 1.0.3

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
Released最后发布2016年3月

Javier Laguna维护。



  • 作者
  • Javier Laguna

SimpleTableView 是一种简单的方式,通过 NSFetchedResultsController 连接到 CoreData 通过一个具有分页功能的 tableView 来使用.tableView。

用法

SimpleTableView 继承自 UITableView。它由 tableView、PaginationView 和 NSFetchedResultsController 组成。

分页是一种有控制地从外部来源检索内容的方式。当在 tableView 的末尾附近滚动时,将调用分页机制。这由 paginationOffset 属性控制,默认情况下,此属性包含 5,基于理想的每页内容大小为 10 项。

PaginationView 可以由您的自定义类扩展。它包含一个 UIActivityIndicatorView,在未隐藏时会旋转,旁边还有一个 UILabel,您可以配置其文本和外观。kSTVPaginatingViewHeight 包含此视图的尺寸。

fetchResultsController 需要配置并注入,但这不是强制的。

为了刷新表格内容,可以通过启用拉动刷新来进行,在顶部显示 UIRefreshControl。这连接到刷新代理方法,这样您可以选择正确的行为。

当通过 NSFetchedResultsController 连接到 Coredata 时,可以利用代理方法 didUpdateItemAtIndexPath,这将让您知道需要更新的单元格索引,但更新实现取决于开发者。

STVTableView

创建

#import "STVSimpleTableView.h>
....

@property (nonatomic, strong) STVSimpleTableView *tableView;
....

- (STVSimpleTableView *)tableView
{
    if (!_tableView)
    {
        _tableView = [[STVSimpleTableView alloc] initWithFrame:CGRectMake(0.0f,
                                                                          kNavigationBarHeight,
                                                                          self.view.bounds.size.width,
                                                                          self.view.bounds.size.height - kNavigationBarHeight)];

        _tableView.backgroundColor = [UIColor lightGrayColor];

        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.allowsSelection = NO;
        _tableView.paginatingView = self.paginatingView;
        _tableView.emptyView = self.emptyView;
        _tableView.loadingView = self.loadingView;
        _tableView.paginationOffset = @(5);
    _tableView.sectionToCheckForData = @(0);

        _tableView.dataSource = self;
    _tableView.delegate = self;
        _tableView.dataRetrievalDelegate = self;
        _tableView.fetchedResultsController = self.fetchedResultsController;
    }

    return _tableView;
}

刷新

- (void)refresh
{
    //This method is called after pull to refresh so it would be good implementing logic to
    //populated the datasource.

    //An animation has been triggered for the UIRefreshControl.

     [JSCFeedAPIManager retrieveFeedWithMode:JSCDataRetrievalOperationModeFirstPage
                                    Success:^(id result)
     {
         BOOL hasContent = weakSelf.fetchedResultsController.fetchedObjects.count > 0;

         [weakSelf.tableView didRefreshWithContent:hasContent];
         [weakSelf.tableView reloadData];
     }
                                    failure:^(NSError *error)
     {
         BOOL hasContent = weakSelf.fetchedResultsController.fetchedObjects.count > 0;

         [weakSelf.tableView didRefreshWithContent:hasContent];
     }];
}

- (void)didUpdateItemAtIndexPath:(NSIndexPath *)indexPath
{
    //A specific item has changed in Coredata, you might update the cell containing this item.
}

STVPaginationView

创建

#import <STVPaginatingView.h>
....

@property (nonatomic, strong) STVPaginatingView *paginatingView;
....

- (STVPaginatingView *)paginatingView
{
    if (!_paginatingView)
    {
        _paginatingView = [[STVPaginatingView alloc] initWithFrame:CGRectMake(0.0f,
                                                                              0.0f,
                                                                              self.view.bounds.size.width,
                                                                              kSTVPaginatingViewHeight)];

        _paginatingView.loadingLabel.text = NSLocalizedString(@"Loading", nil);
    }

    return _paginatingView;
}                                                       

分页

- (void)paginate
{
    [self.tableView willPaginate]; // Will trigger a pagination animation.

    //This method is called when the table view is near to present the last few cells it would good implementing logic to
    //populated the datasource.

    [self.tableView didPaginate] // Will finish the pagination animation and prepare the tableView for a new pagination if needed.
}

空视图

可选视图,当没有数据时自动显示。唯一的要求是它基于 UIView 构建。

用法

- (STVSimpleTableView *)tableView
{
    if (!_tableView)
    {
...
    _tableView.emptyView = self.emptyView;
...

示例

创建
#import "JSCEmptyView.h"

/**
 View to show when no data is available.
 */
@property (nonatomic, strong) JSCEmptyView *emptyView;

...
- (JSCEmptyView *)emptyView
{
    if (!_emptyView)
    {
        _emptyView = [[JSCEmptyView alloc] initWithFrame:CGRectMake(0.0f,
                                                                    0.0f,
                                                                    self.view.bounds.size.width,
                                                                    self.view.bounds.size.height)];

        _emptyView.messageLabel.text = NSLocalizedString(@"NoContentBody", nil);
    }

    return _emptyView;
}

加载视图

在获取数据时自动显示的可选视图。唯一的要求是它是基于UIView构建的。

用法

- (STVSimpleTableView *)tableView
{
    if (!_tableView)
    {
...
    _tableView.loadingView = self.loadingViews;
...

示例

创建
#import "JSCLoadingView.h"

/**
 View to show while data is being loaded.
 */
@property (nonatomic, strong) JSCLoadingView *loadingView;

...
- (JSCLoadingView *)loadingView
{
    if (!_loadingView)
    {
        _loadingView = [[JSCLoadingView alloc] initWithFrame:CGRectMake(0.0f,
                                                                        0.0f,
                                                                        self.view.bounds.size.width,
                                                                        self.view.bounds.size.height)];
    }

    return _loadingView;
}

sectionToCheckForData

如果您对特定部分的内容感兴趣,可以使用此可选值。这在某些部分有固定内容而只想检查将包含实际内容的特定部分时非常有用。

用法
- (STVSimpleTableView *)tableView
{
    if (!_tableView)
    {
...
    _tableView.sectionToCheckForData = @(0);
...

发现一个问题?

如果您遇到与EasyAlert特定的问题,或有一个功能请求,或想分享评论,请在此处创建新问题

我们鼓励并非常感激Pull Request!请尽量保持与现有编码风格的一致性。如果您考虑对项目进行重大更改或增加,请通过打开新问题提前进行沟通。这允许每个人都参与即将到来的更改,确保更改与项目的设计哲学相一致,并避免重复劳动。

感谢您!