【问题标题】:Pull To Refresh issue with TableViewTableView 的拉取刷新问题
【发布时间】:2015-07-04 10:20:02
【问题描述】:

我已经用两个自定义原型单元格在 UITableview 中添加了拉动刷新,我已经尝试使用这两种类型的代码,一种是通过添加 UIRefreshcontrol 作为 tableview 的子视图,另一种是通过 UITableViewController

1)UIRefreshcontrol作为tableview的子视图

self.refreshControl = [[UIRefreshControl alloc] init];
self.refreshControl.tintColor = [UIColor blackColor];
[self.refreshControl addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged];
[listTable addSubview:self.refreshControl];

2)通过 UITableViewController

UITableViewController *tableViewController = [[UITableViewController alloc] init];
tableViewController.tableView = listTable;

self.refreshControl = [[UIRefreshControl alloc] init];
[self.refreshControl addTarget:self action:@selector(refreshContacts) forControlEvents:UIControlEventValueChanged];
tableViewController.refreshControl = self.refreshControl;

但它们似乎都不起作用。

【问题讨论】:

  • 看看我的回答老兄

标签: ios objective-c iphone uitableview uirefreshcontrol


【解决方案1】:

查看这些链接以获取信息

UIRefreshControl - Pull To Refresh in iOS 7

http://www.techrepublic.com/blog/software-engineer/better-code-implement-pull-to-refresh-in-your-ios-apps/

例子

UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
refreshControl.backgroundColor = [UIColor clearColor];
refreshControl.tintColor = [UIColor whiteColor];
[refreshControl addTarget:self
                   action:@selector(getLatestData)
         forControlEvents:UIControlEventValueChanged];

[yourTableviewName addSubview:refreshControl];


   -(void)getLatestData
{
 // here add your reload method
  [self XXXXX]; 

  NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  [formatter setDateFormat:@"MMM d, h:mm a"];
   NSString *title = [NSString stringWithFormat:@"Last update: %@", [formatter stringFromDate:[NSDate date]]];
   NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:[UIColor whiteColor]
                                                                    forKey:NSForegroundColorAttributeName];
   NSAttributedString *attributedTitle = [[NSAttributedString alloc] initWithString:title attributes:attrsDictionary];
        refreshControl.attributedTitle = attributedTitle;

        [refreshControl endRefreshing];
    }

【讨论】:

  • @selector 本身没有被调用,当我向下拖动 tableview 时我找不到活动指示器
【解决方案2】:

第二种方式与我在What's the Best Way to Get a "Pull to Refresh" from a UITableView? 中建议的代码几乎相同,所以我认为您的错误在tableViewController 中。它会被保留吗?

【讨论】:

  • tableview 约束问题会影响刷新控制吗??
  • 我不确定,但我认为您的代码的问题是您的 UITableViewController 没有被保留(我可以看到);您的其他变量都没有引用它。如果你的 UITableViewController 被 ARC 释放,tableViewController.refreshControl = self.refreshControl; 不会做任何事情。我的猜测是,如果你将 tableViewController 作为一个强属性添加到你的对象中,这段代码应该可以工作。
【解决方案3】:

在.h中

@property(nonatomic,strong) UIRefreshControl *refreshControl;

.m

- (void)viewDidLoad {
    [super viewDidLoad];
 //Initialize the refresh control
    self.refreshControl = [[UIRefreshControl alloc] init];
    [self.refreshControl addTarget:self action:@selector(refreshBrandList:) forControlEvents:UIControlEventValueChanged];
    [self.tableView addSubview:self.refreshControl];

}


-(void) refreshBrandList:(id)sender{
    [self ServiceCall];
    [self.refreshControl endRefreshing];


}

【讨论】:

  • 我已经在使用这段代码,请提出其他不同的答案
  • 你的问题是你的选择器不工作或者你没有看到刷新图标
  • 我没有看到刷新图标和@selector 工作
【解决方案4】:

SVPullToRefresh + SVInfiniteScrolling

  • 易于使用。
  • 提供下拉刷新

Easy to add pull-to-refresh and infinite scrolling fonctionalities to any UIScrollView or UITableView

【讨论】:

  • 使用这个我们可以将刷新图标的框架更新低一点吗? ,我在最上面找到刷新图标所以,它不是完全可见的
  • 是的,你可以。您需要在 SvPullToRefreshView 类中使用白色大号编辑 UIActivityIndi​​catorView 样式,并根据需要放置适当的色调。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多