【问题标题】:ios7: Pull to refresh does not show up on simulatorios7:拉动刷新不会出现在模拟器上
【发布时间】:2014-07-28 23:13:18
【问题描述】:

我对@9​​87654322@ 编程很陌生,对于一个班级项目,我试图实现“拉动刷新功能”

我从这个link 尝试过,并在我的MoviesViewController 中实现了同样的功能

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.moviesTableView.delegate = self;
    self.moviesTableView.dataSource = self;

    // pull to refresh
    UIRefreshControl *refresh = [[UIRefreshControl alloc] init];
    refresh.attributedTitle = [[NSAttributedString alloc] initWithString:@"Pull to Refresh"];
    [refresh addTarget:self action:@selector(refreshView:) forControlEvents:UIControlEventValueChanged];
    self.refreshControl = refresh;

    // progress bar
    MBProgressHUD *HUD = [self getLoadingController];
    [HUD showWhileExecuting:@selector(generateMovies) onTarget:self withObject:nil animated:YES];

    self.moviesTableView.rowHeight = 100;
    [self.moviesTableView registerNib:[UINib nibWithNibName:@"MovieViewCell" bundle:nil] forCellReuseIdentifier:@"MovieViewCell"];
}

-(void)refreshView:(UIRefreshControl *)refresh {
    refresh.attributedTitle = [[NSAttributedString alloc] initWithString:@"Refreshing data..."];

    // custom logic: get data from server
    NSLog(@"refreshing view");


    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"MMM d, h:mm a"];
    NSString *lastUpdated = [NSString stringWithFormat:@"Last updated on %@",[formatter stringFromDate:[NSDate date]]];
    refresh.attributedTitle = [[NSAttributedString alloc] initWithString:lastUpdated];
    [refresh endRefreshing];
}

但是当我在模拟器中运行它时,我在拉下电影表时看不到它。

这可能是什么问题?

【问题讨论】:

  • 你有UITableViewController,还是计划UIViewController?它看起来像一个普通的 UIViewController,因为您显然是在引用一个 UITableView 并设置它的数据源和委托。如果是这样,我认为 UIRefreshControl 在这种情况下将不起作用。我相信它只适用于 UITableViewController 实例。
  • 我想你忘了在 UITableView 中添加子视图 UIRefreshControl .. 试试 [self.tblVideoView addSubview:refresh];
  • 添加刷新控件在模拟器中不起作用,但它在我的设备上起作用。

标签: ios pull-to-refresh


【解决方案1】:

我认为您没有将 HUD 添加到刷新控件中。根据您的视图结构,您需要以下内容:

[self.refreshLoadingView addSubview:self.hud];

我们需要查看您的其余代码来调试问题,但这是我写的一个教程,解释了适用于 iOS(包括 Swift)的自定义下拉刷新控件:http://www.jackrabbitmobile.com/design/ios-custom-pull-to-refresh-control/

【讨论】:

    猜你喜欢
    • 2014-08-21
    • 2017-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-22
    • 1970-01-01
    相关资源
    最近更新 更多