我有一個UIViewController
,它有一個UITableView
作爲subView
。我正試圖在桌面上添加一個拉到刷新。 我有UIRefresh
顯示,但它從來沒有調用選擇器。我沒有收到有關拉動行動的通知。 因爲我使用這個查看我的通用視圖我不能使用TableView
控制器,這樣我可以使用多個視圖控制器UIViewController中的UIRefreshControl
- (void)viewDidLoad{
[super viewDidLoad];
// Refresh control
UITableViewController *tableViewController = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
tableViewController.tableView = self.genericMainTableView;
// Initialise refresh control
self.refreshControl = [[UIRefreshControl alloc] init];
//Adding target to refresh Control object
[self.refreshControl addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged];
//Setting attribute Title
self.refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull To Refresh"];
//Adding as subview to tableView
tableViewController.refreshControl = self.refreshControl;
}
- (void)refresh:(UIRefreshControl *)refreshControl {
reachability = [Reachability reachabilityForInternetConnection];
NetworkStatus netStatus = [reachability currentReachabilityStatus];
//Not Reachable - No Internet Connection
if (netStatus == NotReachable) {
[[[UIAlertView alloc]initWithTitle:@"Network Error" message:@"Please Check your Network Connection" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]show];
[refreshControl endRefreshing];
}
else{
//My Function Call
[self functionCall];
//Reload the Table
[self.genericMainTableView reloadData];
//set the title while refreshing
refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing the TableView"];
//set the date and time of refreshing
NSDateFormatter *formattedDate = [[NSDateFormatter alloc]init];
[formattedDate setDateFormat:@"MMM d, h:mm a"];
NSString *lastupdated = [NSString stringWithFormat:@"Last Updated on %@",[formattedDate stringFromDate:[NSDate date]]];
refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:lastupdated];
//End Refreshing
[refreshControl endRefreshing];
}
}
上午我在這裏所做的一切。它不適合我。請幫助我。
感謝您的評論:)但我也試過,但它不工作。 – Wodjefer
嘗試重命名您的選擇器,然後 – iBug
對不起沒有工作:(。 – Wodjefer