वास्तविक समस्या यह है कि कैसे गतिशील और स्थैतिक तालिका दृश्य नियंत्रक काम करते हैं।
यदि आप एक गतिशील UITableViewController बनाते हैं, तो अधिकांश विधियां शून्य या 0 या अन्य डिफ़ॉल्ट मान लौटाती हैं। इसलिए यदि आप अपने UITableViewController उपclass में उन्हें ओवरराइट नहीं करते हैं तो कुछ भी बुरा नहीं होता है।
यदि आप एक स्थिर UITableViewController बनाते हैं, तो अधिकांश विधियां स्टोरीबोर्ड को "पूछने" के लिए क्या पूछती हैं। हकीकत में शायद एक बैकिंग स्टोर के रूप में एक निजी सरणी की तरह कुछ है जिसमें सभी आवश्यक डेटा शामिल हैं। और यदि आप इस बैकिंग स्टोर से पूछताछ करने वाले तरीकों को ओवरराइट नहीं करते हैं तो डिफ़ॉल्ट कार्यान्वयन उन इंडेक्स पर ऑब्जेक्ट्स के लिए सरणी से पूछेगा जो मौजूद नहीं हैं।
आपकी समस्या यह है कि आप तालिका बताते हैं कि इसमें 2 अनुभाग और कुछ पंक्तियां हैं।तो tableView स्थिर UITableViewController से दूसरी पंक्ति में दूसरी पंक्ति में सेल की ऊंचाई जैसी चीज़ों के बारे में पूछता है। लेकिन यह इंडेक्सपैथ बैकिंग स्टोर में मौजूद नहीं है (क्योंकि आप केवल दूसरे पंक्ति में एक पंक्ति डालते हैं) जिसका उपयोग स्थिर तालिका दृश्य द्वारा किया जाता है।
तो आपको कुछ डेटा स्रोत और प्रतिनिधि विधियों को लागू करना होगा और तालिका दृश्य दृश्य तालिका स्टोर में मौजूद जानकारी तक पहुंचने के लिए अपने मूल्यों को वापस करना होगा।
यदि आप अपवाद के कॉल स्टैक को देखते हैं तो आपको इन विधियों को देखने में सक्षम होना चाहिए।
उदा .:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
*** First throw call stack:
(
0 CoreFoundation 0x000000010ebaaf35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010e843bb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010eaa301e -[__NSArrayI objectAtIndex:] + 190
3 UIKit 0x000000010f4dc856 -[UITableViewDataSource tableView:heightForRowAtIndexPath:] + 109
4 UIKit 0x000000010f21026b __66-[UISectionRowData refreshWithSection:tableView:tableViewRowData:]_block_invoke + 302
5 UIKit 0x000000010f20f8fe -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 4125
6 UIKit 0x000000010f214e45 -[UITableViewRowData rectForFooterInSection:heightCanBeGuessed:] + 320
7 UIKit 0x000000010f214f3a -[UITableViewRowData heightForTable] + 56
कॉल स्टैक के सूचकांक 3 में आप देख सकते हैं कि -[UITableViewDataSource tableView:heightForRowAtIndexPath:]
objectAtIndex:
कोड है कि अपवाद उठाया आह्वान किया है। यह उन तरीकों में से एक है जो बैकएंड स्टोर में अपनी कॉल रिले करते हैं यदि आप उन्हें ऐसा करने से नहीं रोकते हैं। तो आपको इस विधि को लागू करना होगा और कुछ उपयोगी वापस करना होगा। और तब तक आप जारी रहते हैं जब तक कि कोई अपवाद नहीं है।
आपकी तालिका की कॉन्फ़िगरेशन पर कितनी विधियों की आवश्यकता हो सकती है। मैं चार है कि आमतौर पर इन अपवादों के कारण लागू किया है, तो आप पैटर्न आप का पालन करना चाहिए यदि आप और अधिक अपवाद नहीं ओवरराइट UITableViewDataSource/प्रतिनिधि तरीकों की वजह से कर रहे हैं देख सकते हैं:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
CGFloat height = 0;
if (section == 0) {
// static section
height = [super tableView:tableView heightForHeaderInSection:section];
}
return height;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
CGFloat height = 0;
if (section == 0) {
// static section
height = [super tableView:tableView heightForFooterInSection:section];
}
return height;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
CGFloat height = 44;
if (indexPath.section == 0) {
// static section
height = [super tableView:tableView heightForRowAtIndexPath:indexPath];
}
return height;
}
- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath {
NSInteger indentationLevel = 0;
if (indexPath.section == 0) {
// static section
indentationLevel = [super tableView:tableView indentationLevelForRowAtIndexPath:indexPath];
}
return indentationLevel;
}
और यहाँ एक छोटे से है आप गतिशील और स्थिर कोशिकाओं मिश्रण हैं, तो बुला super
बहुत उपयोगी हो जाता है
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == 0) {
// static section
return [super tableView:tableView numberOfRowsInSection:section];
}
return self.objects.count;
}
: अपने स्थैतिक सामग्री और भी अधिक अपने कोड से स्वतंत्र बनाने के लिए चाल।
इस http://stackoverflow.com/a/9428324/285190 – Flexicoder
पर एक नज़र डालें मैं नहीं दिख रहा है कि कैसे अपनी कड़ी में मदद कर किया जाना चाहिए इस मामले के रूप में वर्णित समस्याओं के बराबर मेरे बराबर नहीं है, इसके अलावा मैं एक UITableViewController का उपयोग कर रहा हूं और UIViewController – CRE8IT
नहीं, यह नंबरऑफरोइनसेक्शन के ठीक बाद दुर्घटनाग्रस्त हो जाता है और सेलफ़ोररोएट इंडेक्सपैथ – CRE8IT