में एक अनुभाग पाद लेख दृश्य जोड़ने पर क्रैश यह पहली बार है जब मैं यहां एक प्रश्न पूछता हूं, लेकिन मुझे यह कहना है कि पिछले कुछ महीनों में यह साइट मेरे लिए जबरदस्त मदद रही है (iphone-dev- बुद्धिमान), और मैं इसके लिए धन्यवाद।UITableView: रिक्त अनुभाग
हालांकि, मुझे इस समस्या के लिए कोई समाधान नहीं मिला है: मेरे पास 2 अनुभागों के साथ एक UITableView है, और पहली बार ऐप लॉन्च होने पर कोई पंक्ति नहीं है। उपयोगकर्ता बाद में अनुभागों को भर सकता है जैसा वह चाहता है (सामग्री यहां प्रासंगिक नहीं है)। पंक्तियों से भरे जाने पर UITableView अच्छा दिखता है, लेकिन जब कोई नहीं होता है तो बहुत बदसूरत लग रहा है (2 हेडर अनुभाग एक साथ सफेद जगह के साथ अटक गए हैं)। यही कारण है कि जब कोई पंक्ति नहीं है, तो मैं एक अच्छा "कोई पंक्ति" दृश्य जोड़ना चाहता हूं।
मैं viewForFooterInSection प्रयोग किया है:
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
if(section == 0)
{
if([firstSectionArray count] == 0)
return 44;
else
return 0;
}
return 0;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
if(section == 0)
{
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(200, 10, 50, 44)];
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor colorWithWhite:0.6 alpha:1.0];
label.textAlignment = UITextAlignmentCenter;
label.lineBreakMode = UILineBreakModeWordWrap;
label.numberOfLines = 0;
label.text = @"No row";
return [label autorelease];
}
return nil;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if(section == 0)
{
return [firstSectionArray count];
}
return [secondSectionArray count];
}
यह महान काम करता है: पाद लेख दृश्य दिखाई देता है वह भी तब, खंड 0. में कोई पंक्ति है लेकिन मेरी ऐप्लिकेशन क्रैश जब मैं संपादन मोड में प्रवेश करने और खण्ड के अंतिम पंक्ति हटाएँ 0:
अभिकथन विफलता में - [UIViewAnimation initWithView: indexPath: endRect: endAlpha: startFraction: endFraction: वक्र: animateFromCurrentPosition: shouldDeleteAfterAnimation: संपादन:] समाप्त एप्लिकेशन न आया हुआ अपवाद के कारण 'NSInterna lInconsistencyException ', कारण:' सेल एनीमेशन रोक अंश अधिक होना चाहिए की तुलना में अंश शुरू '
यह जब वहाँ अनुभाग 0 में कई पंक्तियों हैं ऐसा नहीं होता है यह केवल तब होता है जब वहाँ केवल एक ही पंक्ति छोड़ दिया है।
यहाँ संपादन मोड के लिए कोड है:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
// If row is deleted, remove it from the list.
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Find the book at the deleted row, and remove from application delegate's array.
if(indexPath.section == 0)
{ [firstSectionArray removeObjectAtIndex:indexPath.row]; }
else
{ [secondSectionArray removeObjectAtIndex:indexPath.row]; }
// Animate the deletion from the table.
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationBottom];
[tableView reloadData];
}
}
किसी को भी किसी भी विचार क्यों यह हो रहा है है? धन्यवाद
आप मेरे नायक हैं! "कोई डेटा" सेल 2 पिक्सल छोटे बनाना इसे सब काम करता है! आपको बहुत - बहुत धन्यवाद! (और एफवाईआई, मैंने पहले ही दूसरे समाधान के बारे में सोचा था लेकिन इसे काम नहीं कर सका) मुझे अभी भी थोड़ी सी समस्या है: तालिका 0 में कोई पंक्ति नहीं होने पर तालिकादृश्य की पृष्ठभूमि अब सफेद है जब मुझे यह बेहतर लगता है यह खाली कोशिकाओं से भरा था (यहां छवि देखें: http://yfrog.com/izuitableviewproblemp)। कोई टिप? फिर से धन्यवाद डेविड, आपने मेरा दिन बनाया! – nmondollot
कोई शानदार विचार नहीं है, शायद एक अलग सवाल के लायक है। –
ठीक है, मैंने यही किया है। धन्यवाद – nmondollot