2010-08-12 15 views
7

नहीं निकाल दिया गया है मेरे पास spliewViewController है जो MasterViewController के रूप में कुछ दृश्य नियंत्रक के रूप में है और DetailViewController के रूप में कुछ tableViewController है। जब मैं मास्टरव्यू कंट्रोलर पर एक बटन दबाता हूं, तो मैं मौजूदा तालिका के बजाय विवरण में नया टेबल व्यू कंट्रोलर दिखाना चाहता हूं।UITableView reloadData - cellForRowAtIndexPath को

SearchDetailViewController *searchDetailViewController = [[SearchDetailViewController alloc] initWithStyle:UITableViewStylePlain]; 
UINavigationController *searchDetailNavigationController = [[UINavigationController alloc] initWithRootViewController:searchDetailViewController]; 

मैं नए tableController में दिखाने के लिए डेटा गुजर रहा है कि बाद:

[searchDetailViewController passInSearchResults:listOfItems]; 

है कि मैं "पुश" splitViewController करने के लिए नए नियंत्रक के बाद:

तो मैं इस तरह किया

[searchSplitViewController setViewControllers:[NSArray arrayWithObjects:self.navigationController, searchDetailNavigationController, nil]]; 

लक्ष्य तालिका में व्यू कंट्रोलर विधि "passInSearchResults" डेटा पास हो गया है और मैं reloadDa भी कॉल करता हूं टा। विधि इस तरह दिखता है:

- (void)passInSearchResults:(NSMutableDictionary *)searchResults { 
    self.searchResultList = searchResults; 
    NSLog(@"Data is passed in: %@",self.searchResultList); 
    [self.tableView reloadData]; 
    //[self.tableView setNeedsDisplay]; 
} 

कंसोल: डेटा में पारित हो जाता है: [यहाँ मैं सटीक डेटा मैं चाहते हैं और यह सिर्फ सही लगता है]।

After this I see that method "numberOfRowsInSection" is fired: 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    NSLog(@"Setting table length: %i",[self.searchResultList count]); 
    return [self.searchResultList count]; 
} 

कंसोल: सेटिंग तालिका लंबाई: [यहाँ मैं उचित लंबाई प्राप्त]

समस्या यह है कि टेबल पारित कर दिया डेटा और विधि "cellForRowAtIndexPath" से भरा नहीं है है नहीं बुलाया जाता है।

यह कैसे हो सकता है कि पुनः लोडडेटा विधि "numberOfRowsInSection" को निकाल दिया गया है लेकिन विधि "cellForRowAtIndexPath" नहीं है ... ???

धन्यवाद

उत्तर

4

कैसे यह है कि reloadData विधि "numberOfRowsInSection" पर हो सकता है निकाल दिया जाता है, लेकिन नहीं विधि "cellForRowAtIndexPath" ... ???

उसी दिन (आईएसएच) मुद्दे के साथ एक दिन बिताने के बाद, मुझे लगता है कि हमें यहां एक बग मिली है। हालांकि मुझे एक हैक/कामकाज मिला।

यदि मैं सरणी को जोड़ता/जोड़ता हूं या पूरी तरह से इसे फिर से बना रहा हूं) जिसका उपयोग मेरे सेलफॉररोएट इंडेक्सपैथ विधि में किया जाता है, तो यह फिर से लोड होने पर सेलफॉररोएट इंडेक्सपैथ को सही ढंग से कॉल करता है।

उदाहरण के लिए, मेरी cellForRowAtIndexPath में मैं की तरह कुछ है:

cell.textLabel.text = [[[self.searchResultsArrayWithSections objectAtIndex:indexPath.section] objectForKey:@"rowValues"] objectAtIndex:indexPath.row]; 

    return cell; 

मैं भी इस सरणी viewDidLoad पर बुलाया जाता है कि निर्माण करने के लिए एक विधि है:

- (NSMutableArray *)splitIntoSectionsWithAlphabet:(NSMutableArray *)myArray 
{  
NSString *letters = @"abcdefghijklmnopqrstuvwxyz"; 
NSMutableArray *content = [NSMutableArray new]; 

//code to build array here, nothing special really 

return content; 
} 

तो मैंने देखा है कि अगर मैं विशेष रूप से इस खोज को मेरी खोज पर कॉल करें RealsDrultsArrayWithSections सरणी reloadData को कॉल करने से पहले, यह वास्तव में सभी UITableViewDelegate विधियों को सही ढंग से कॉल करता है! (जैसे मैंने कहा, हैक लेकिन यह काम करता है!)

//dirty hack, bug with cancel button and not realoding data, seems we have to modify this array before it will work correctly 
self.customerListArrayWithSections = [self splitIntoSectionsWithAlphabet:self.customerListArray]; 
[self.customerListTv reloadData]; 
1

मुझे एक ही समस्या थी, लेकिन निर्णय बहुत आसान था। सबसे पहले, क्या आप तालिका को नीचे स्क्रॉल करने का प्रयास कर सकते हैं? tableView: cellForRow ... कहा जाना चाहिए। हेडर की ऊंचाई और सामग्री के लिए जांचें तालिका दृश्य के लिए ऑफ़सेट।

10

चेक, अगर आप जब [self.tableView reloadData];

- (void)passInSearchResults:(NSMutableDictionary *)searchResults { 
if ([NSThread isMainThread]) { 
    self.searchResultList = searchResults; 
    NSLog(@"Data is passed in: %@",self.searchResultList); 
    [self.tableView reloadData]; 
} 
else { 
    [self performSelectorOnMainThread:@selector(passInSearchResults:) searchResults waitUntilDone:NO]; 
} 

+1

यह जांचना आवश्यक नहीं है कि आप पहले मुख्य धागे पर चल रहे हैं। 'performSelectorOnMainThread' काम करता है, भले ही आप पहले से ही मुख्य थ्रेड पर हों, जैसा कि' dispatch_async (dispatch_get_main_queue() '(जो शायद आप वास्तव में यहां चाहते हैं) है। 'अगर' यहां जोड़ना अनावश्यक प्रोसेसर चक्र का उपभोग करता है। –

4

बुला} अपने numberOfRows चेक, अगर यह 0 मुख्य थ्रेड में हैं, वहाँ प्रदर्शित करने के लिए कोई कोशिकाएं होती हैं।

0

इसके अलावा आप init [के साथ ...] विधि नियंत्रक की विधि आवंटित कर सकते हैं और आईबी में भी उसी संपत्ति को तारित कर सकते हैं। इस तरह यह संभव है कि संख्या ... प्रतिनिधि विधियों को बुलाया जाता है और cellForRow ... नहीं करता है।

0

मेरा "ऑटोलायआउट" UITableView ने reloadData पर cellForRowAtIndexPath को कॉल नहीं किया, क्योंकि मैंने गलती से फ्रेम सेट किया था।

_tableView = [[UITableView alloc] initWithFrame:self.view.frame]; 
_tableView.translatesAutoresizingMaskIntoConstraints = NO; 

CGRectZero करने के लिए इसे बदल कर, यह काम किया ..

_tableView = [[UITableView alloc] initWithFrame:CGRectZero]; 
_tableView.translatesAutoresizingMaskIntoConstraints = NO; 
2

मेरे मामले समस्या यह है कि reloadData() समारोह मुख्य थ्रेड से आमंत्रित नहीं किया गया था।

मैं एक dispatch_async() समारोह है, जो समस्या हल में रखकर यह बदल गया है:

dispatch_async(dispatch_get_main_queue(), { 
    self.tableView.reloadData() 
}) 

आशा इस दूसरों मदद करता है।

संबंधित मुद्दे