Sto cercando di implementare il UIRefreshControl
nella mia applicazione. Ho un file xib e ho aggiunto un UITableViewController
al file pennino vuoto e ho impostato la proprietà di aggiornamento su "enabled". Inoltre ho aggiunto il codice allo viewDidLoad
e un metodo di aggiornamento personalizzato. Il problema è che ho un errore non riesco a trovare alcuna informazione su .... nel mio viewDidLoad
ottengo "Proprietà 'refreshControl
' non trovato in oggetto di tipo ViewController
"Problemi di UIRefreshControl
- (void)viewDidLoad{
[super viewDidLoad];
self.myTableView =
[[UITableView alloc] initWithFrame:self.view.bounds
style:UITableViewStyleGrouped];
self.myTableView.autoresizingMask = UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight;
self.myTableView.delegate = self;
self.myTableView.dataSource = self;
[self.view addSubview:self.myTableView];
UIRefreshControl *refresh = [[UIRefreshControl alloc] init];
refresh.attributedTitle = [[NSAttributedString alloc] initWithString:@"Pull to Refresh"];
[refresh addTarget:self action:@selector(refreshView:) forControlEvents:UIControlEventValueChanged];
self.refreshControl = refresh;
}
-(void)refreshView:(UIRefreshControl *)refresh {
refresh.attributedTitle = [[NSAttributedString alloc] initWithString:@"Refreshing data..."];
// custom refresh logic would be placed here...
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];
}
ho idea perché quella la proprietà non è disponibile .... cosa mi manca?
Sembra che io debba ereditare da UITableViewController
nel mio file ViewController.h
. Se ho già UITableView
come posso ereditare da entrambi? Se cambio il mio codice ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
-ViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource>
poi ho un errore:
error: NSInternalInconsistencyException',
reason: '-[UITableViewController loadView] loaded the "ViewController_iPhone" nib but didn't get a UITableView.'
Questo non è supportato e potrebbe rompersi nella versione futura di iOS. L'unico modo supportato per usare un 'UIRefreshControl' è con un' UITableViewController'. –
@ ACB, questo è esattamente quello di cui avevo bisogno !!! Grazie mille. Vorrei poterti dare più oggetti di scena! – brianhevans
Sì, è possibile avere un UIRefreshControl su una classe UIViewController con UITableView e aggiunti manualmente. I commenti altre risposte potrebbero essere vere (non va con i documenti), ma questo piccolo hack funziona su iOS6. –