2014-06-08 32 views
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個卵巢表。

這裏有什麼問題?

+0

您是否有UITableViewController或計劃UIViewController?它看起來像一個普通的UIViewController,因爲你顯然引用了一個UITableView並設置它的dataSource和delegate。如果是這樣,我認爲UIRefreshControl在這樣的情況下不起作用。我相信它只適用於UITableViewController實例。 – mbm29414

+0

我想你忘了添加在UITableView中查看UIRefreshControl ..試試[self.tblVideoView addSubview:refresh]; –

回答

0

我想你錯過了將HUD添加到刷新控件中。根據您的視圖結構,你需要這樣的:

[self.refreshLoadingView addSubview:self.hud]; 

我們就需要看你的代碼的其餘部分調試問題,但這裏有一個教程,我寫的解釋定製拉來刷新控件對於iOS(包括Swift):http://www.jackrabbitmobile.com/design/ios-custom-pull-to-refresh-control/