यदि आप तालिकादृश्य कक्ष को स्थायी रूप से हटाना चाहते हैं, तो बस अपनी पंक्ति के अनुरूप इंडेक्सपैथ के साथ deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone]
पर कॉल करें। आपको numberOfRowsInSection:
द्वारा लौटाई गई पंक्तियों की संख्या में भी कमी करने की आवश्यकता होगी।
हालांकि, मैं अस्थायी रूप से एक स्थिर तालिकादृश्य से अवांछित स्थिर तालिकादृश्य कक्षों को "हटाएं" करने का एक तरीका ढूंढ रहा था, क्योंकि मैं कभी-कभी एक विशेष पंक्ति चाहता था, और अन्य बार नहीं। मैं भी tableview नियंत्रक के बाहर से मांग पर इसे अद्यतन करने में सक्षम होना चाहता था।
मेरा मामला काफी सरल है, क्योंकि यह पहली पंक्ति है जिसे दिखाया या छुपाया जा रहा था। आप अपनी जरूरतों के अनुसार सामान्यीकृत कर सकते हैं। मेरा टेबलव्यू नियंत्रक मेरा डेटा स्रोत प्रतिनिधि है।
पहले, मैं राज्य चर का अद्यतन करें और पुन: प्रदर्शित गति प्रदान करने के tableview नियंत्रक में एक सार्वजनिक विधि बनाया:
- (void)updateSettingsDisplay:(BOOL)hideSetting
{
if (hideSetting == self.hideSetting) {
return; // no need to do anything because it didn't change
}
self.hideSetting = hideSetting;
self.numRows = (hideSetting)? kNumRowsWithSetting : kNumRowsWithoutSetting;
// redisplay only if we're visible
if (!self.viewJustLoaded && (self.navController.visibleViewController == self)) {
[self.tableView reloadData];
}
self.viewJustLoaded = NO;
}
tableview नियंत्रक के viewDidLoad
लगता है:
- (void)viewDidLoad
{
[super viewDidLoad];
// check whether or not to display out-of-coverage tableview cell
self.hideSetting = YES; // initial value; could just as easily be NO
self.viewJustLoaded = YES;
[self updateSettingsDisplay];
}
tableview के डेटा- स्रोत प्रतिनिधि:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return self.numRows;
}
और अंतिम इसलिए का उपयोग करें कि आपके स्थिर tableview कोशिकाओं की स्थायी भंडारण के लिए - ly
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// set row to the index of the stored tableView cell that corresponds to the
// cell you want (its location in the static tableview from your storyboard)
NSInteger row = indexPath.row;
if (self.hideSetting) {
// skip drawing setting's tableviewcell (since the setting we're hiding is
// first, we can just increment the row to get the one we want)
++row;
assert(row < kTotalRows); // bounds checking just to convince yourself (remove after testing)
}
// get a new index path since the row field is read-only
NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:row inSection:indexPath.section];
// grab the cell from super that corresponds to the cell you want
UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:newIndexPath]; // static table
return cell;
}
चाल है कि स्थिर कोशिकाओं हमेशा [super tableView:tableView cellForRowAtIndexPath:newIndexPath]
में उपलब्ध हैं। फिर आवश्यकतानुसार पंक्तियों की संख्या समायोजित करें, और पंक्तियों को सही ढंग से मानचित्र करें (यानी, अपने सेलव्यू प्रतिनिधि के cellForRowAtIndexPath:
में पंक्तियों को संग्रहीत सेल की पंक्ति प्राप्त करें)।
updateSettingsDisplay
विधि को आपके टेबलव्यू नियंत्रक पर किसी भी वर्ग द्वारा कॉल किया जा सकता है जो इसे बरकरार रखता है। यदि टेबलव्यू नियंत्रक दिखाई देने पर दिखाई नहीं देता है, तो यह केवल राज्य को अपडेट करेगा और अगली बार प्रदर्शित होने के लिए दृश्यमान होने तक प्रतीक्षा करेगा।
दरअसल, यह तरीका एकमात्र तरीका है जिसे मैंने समस्या को हल करने के लिए पाया है, विधि ऊंचाई ForRowAtIndexPath, इंडेक्सपैथ के लिए एक स्विच है और इस फ़ंक्शन के अंदर सत्यापन कर रहा है। यदि यह शून्य है, तो मैं आईबीओलेट यूआईटीबल व्यूसेल संदर्भ के साथ सेल छुपा रहा हूं, और 0 लौटा रहा हूं .. सेल चला गया है! 20 से अधिक कोशिकाओं के होने पर यह थोड़ा डरावना हो रहा है, लेकिन यह अच्छा काम करता है! – Marc
यह सभी समस्याओं को हल करता है https://github.com/xelvenone/StaticDataTableViewController/ –