我对iOS
编程很新,对于我正在尝试实现“拉动刷新功能”的课程项目
我尝试了这个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];
}
但是当我在模拟器中运行时,我在拉下电影表时看不到它。
这可能是什么问题?
答案 0 :(得分:0)
我认为你错过了将HUD添加到刷新控件中。根据您的视图结构,您需要以下内容:
[self.refreshLoadingView addSubview:self.hud];
我们需要查看剩下的代码来调试问题,但是我在这里编写的教程解释了iOS(包括Swift)的自定义pull-to-refresh控件:http://www.jackrabbitmobile.com/design/ios-custom-pull-to-refresh-control/