आप कस्टम TableViewCells का उपयोग कर रहे हैं, तो सामान्य
[self.tableView reloadData];
प्रभावी रूप से इस सवाल का जब तक आप वर्तमान दृश्य छोड़ने के लिए और वापस आने के उत्तर नहीं देता। न तो पहला जवाब है। निम्नलिखित ताज़ा विधि जो ताकि आप कस्टम पुनः लोड कर सकते केवल उपरोक्त विधि करने के लिए कॉल
//For iOS 5 and later
- (void)reloadTopCell {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
NSArray *indexPaths = [[NSArray alloc] initWithObjects:indexPath, nil];
[self.tableView reloadRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone];
}
सम्मिलित:
सफलतापूर्वक विचारों स्विच किए बिना अपना पहला तालिका दृश्य सेल को फिर से लोड करने के लिए निम्न कोड का उपयोग शीर्ष सेल (या पूरी तालिका दृश्य यदि आप चाहें):
- (void)refresh:(UIRefreshControl *)refreshControl {
//call to the method which will perform the function
[self reloadTopCell];
//finish refreshing
[refreshControl endRefreshing];
}
अब आप कि, हल कर अपने viewDidLoad
जोड़ने के अंदर है निम्नलिखित:
//refresh table view
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged];
[self.tableView addSubview:refreshControl];
अब आपके पास कस्टम रीफ्रेश टेबल सुविधा है जो शीर्ष सेल को फिर से लोड करेगी। पूरी तालिका को फिर से लोड करने के लिए,
[self.tableView reloadData];
अपनी नई रीफ्रेश विधि में जोड़ें।
//ensure that it reloads the table view data when switching to this view
- (void) viewWillAppear:(BOOL)animated {
[self.tableView reloadData];
}
स्रोत
2014-10-13 02:03:41
nitpicking यहाँ, लेकिन निश्चित रूप से आप केवल एक ही सेल आप शायद का उपयोग करना चाहें ताज़ा कर रहे थे '[NSArray arrayWithObject:]' बजाय। –
इसके अलावा, इस स्थिति में, 'startUpdates' और' endUpdates' अनावश्यक हैं। – kubi
@ कुबी हाय, क्या आप समझा सकते हैं कि वे क्यों जरूरी नहीं हैं? – Unheilig