2
顯示不出來我是相當新的iOS
編程和一類項目,我試圖實現「拉刷新功能」ios7:拉,刷新模擬器
我從這個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];
}
但當我在模擬器中運行這個,我沒有看到它,而拉低m個卵巢表。
這裏有什麼問題?
您是否有UITableViewController或計劃UIViewController?它看起來像一個普通的UIViewController,因爲你顯然引用了一個UITableView並設置它的dataSource和delegate。如果是這樣,我認爲UIRefreshControl在這樣的情況下不起作用。我相信它只適用於UITableViewController實例。 – mbm29414
我想你忘了添加在UITableView中查看UIRefreshControl ..試試[self.tblVideoView addSubview:refresh]; –