【发布时间】:2014-07-28 23:13:18
【问题描述】:
我对@987654322@ 编程很陌生,对于一个班级项目,我试图实现“拉动刷新功能”
我从这个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