कुछ समय छोड़ कृपया के रूप में यह एक लंबी स्पष्टीकरणUITableViewCell में एक कस्टम सेपरेटर कैसे जोड़ें?
है मैं एक UIViewController
एक UIButton
के होते हैं जो और एक UITableView
जो पहचानकर्ता Cell1
और Cell2
साथ UITableViewCell
रों के विभिन्न प्रकार लोड करता है, बटन की स्थिति touchUpInside
पर है। मैं स्टोरीबोर्ड का उपयोग कर रहा हूँ।
दोनों कक्षों के लिए विभाजक अनुकूलित कर रहे हैं।
Cell1
में एक विभाजक है जो सेल की पूरी चौड़ाई और सेल के नीचे 1 पिक्सेल ऊंचाई पर कब्जा करता है।
जबकि Cell2
में एक विभाजक है जिसने सेल से 5 पिक्सेल ऑफसेट किया है, दोनों बाएं और दाएं।
प्रत्येक बार tableView
के बाहर वाला बटन सेल पहचानकर्ता के आधार पर tableViewCell
एस को बदल दिया गया है।
प्रारंभ में tableView
viewController
की पूरी चौड़ाई पर है और CELL1 के होते हैं, लेकिन बटन, उपयोग किया जाता है tableViewCell
रों CELL2 करने के लिए बदल रहे हैं और tableView
के फ्रेम बदल गया है, चौड़ाई 10 और एक्स-मूल से कम हो जाता है 5.
लेकिन जब ऐसा होता है, तो Cell2
का विभाजक सेल से 5 पिक्सेल दूर है लेकिन बाईं ओर यह 5 पिक्सेल से दूर है। यह सभी Cell2
के लिए होता है जो डेटा के साथ लोड होता है, और जिन कक्षों में कोई डेटा नहीं है, फ्रेम उचित रूप से बदला जाता है।
लेकिन उस के बाद सेल Cell1
की चौड़ाई (बड़ा चौड़ाई) यह करने के लिए सेल कक्षा में साथ विभाजक के लिए किया जाएगा
-(void)setSeperatorStyleForTableView :(UITableViewCell *)cell //this is called in cellForRowAtIndex
{
//cell- type of cell(Cell1 or Cell2)
CGRect seperatorFrame;
UIImageView *seperatorImage;
seperatorFrame = [self setSeperatorFrame:cell];
if(firstCellToBeLoaded)//BOOL used to change the button text and load appropriate cells
{
seperatorImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"table_row
2.png"]];
}
else
{
seperatorImage = [[UIImageView alloc] initWithImage:[UIImage
imageNamed:@"table_row.png"]];
}
seperatorImage.frame = seperatorFrame;
seperatorImage.autoresizingMask = YES;
[cell.contentView addSubview:seperatorImage];
}
//set the customized separator frame
-(CGRect)setSeperatorFrame :(UITableViewCell *)cell
{
CGRect seperatorFrame;
seperatorFrame.size.height = 1.0;
seperatorFrame.origin.y = cell.frame.origin.y + (cell.frame.size.height - 1.0);
if(firstCellToBeLoaded)
{
seperatorFrame.origin.x = cell.frame.origin.x ;
seperatorFrame.size.width = cell.frame.size.width;
}
else
{
seperatorFrame.origin.x = cell.frame.origin.x + 5.0;
seperatorFrame.size.width = cell.frame.size.width -10.0;
}
return seperatorFrame;
}
सामान्य में आपूर्ति कृपया कर सकते हैं, इस काम करता है। हालांकि, जब सेल का चयन/हाइलाइट किया जाता है तो यह टूट जाता है क्योंकि तब सभी सबव्यूव में 'पृष्ठभूमि रंग' पारदर्शी पर रीसेट हो जाता है। 'पृष्ठभूमि रंग' के बजाय, एक सरल 'UIView' उपclass बनाना बेहतर है जो' drawRect: 'में दिए गए रंग के साथ स्वयं भर जाएगा। साथ ही, विभाजक 'सामग्री दृश्य' में नहीं जा सकता (हटाए गए बटन, accesory विचार आदि के कारण)। यह सीधे सेल पर जाना चाहिए। – Sulthan
@ सुल्तान - आप रंग के बजाय छवि भी डाल सकते हैं, मैंने इसे अपने उत्तर की टिप्पणी में भी उल्लेख किया :) धन्यवाद :) – iPatel
अंतिम सेल इस – Mittchel