हम हजारों पंक्तियों या कुछ भी नहीं बोल रहे हैं, हालांकि अगर चीजों को उच्च स्तर तक बढ़ाने का कोई तरीका था, तो मुझे यह पसंद आएगा।UITableView में बड़ी संख्या में पंक्तियों/खंडों को एनिमेट करने से खराब प्रदर्शन
मेरे पास 27 वर्गों और 180 पंक्तियों के साथ एक सारणी है जिसमें सभी वर्गों में फैला हुआ है, और जिस परिदृश्य में मैं वर्तमान में फंस रहा हूं वह यह है कि जब मैं मॉडल मॉडल में चीजों को केवल 3 खंडों और 5 पंक्तियों के साथ एनिमेट करता हूं, और इससे भी बदतर) फिर से वापस।
मैं startUpdates/endUpdates के साथ सभी एनिमेशन बैच कर रहा हूं। मेरा ऐप आईफोन 4 पर 1-2 सेकंड के लिए बहुत अच्छी तरह से लॉक हो जाता है, जबकि यह चीजों को आंकड़ा करता है, फिर एनिमेशन शुरू होता है।
मैंने प्रत्येक पंक्ति को हटाने/जोड़ने के लिए एनिमेट करने और दोनों पंक्तियों को हटाने के मामले में 0 को छोड़ने की कोशिश की है, और केवल अनुभागों को हटाने/सम्मिलित करने के लिए एनिमेट करने की कोशिश की है (जब पंक्ति गणना 0 तक गिर जाएगी)। मैंने माना होगा कि उत्तरार्द्ध बेहतर प्रदर्शन करेगा लेकिन यह चीजों को बिल्कुल नहीं बदलेगा।
क्या ऐसा कुछ भी है जो इसे गति देने के लिए ऐप पर किया जा सकता है? यदि उनमें से 20 से अधिक हैं, तो इसके बजाय मेरे पास केवल पुनः लोड करने का विकल्प चुनने के लिए अलग-अलग एनिमेशन से बाहर निकलने के लिए कोड का एक बड़ा हिस्सा है।
संपादित यहाँ कोड है कि समस्या दर्शाती है। इस कोड का प्रदर्शन बराबर मोनोचच कोड (जो मैं पहले उपयोग कर रहा था) से थोड़ा बेहतर है, लेकिन यह अभी भी बहुत खराब है।
#import "TableViewController.h"
@interface MyTableViewDataSource : NSObject<UITableViewDataSource> {
int rows;
};
@end
@implementation MyTableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (void)setRowCount:(int)r
{
rows = r;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return rows;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.textLabel.text = [NSString stringWithFormat:@"row %d", indexPath.row];
return cell;
}
@end
@implementation MyTableViewController {
UIBarButtonItem *populateButtonItem;
};
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
populateButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Populate" style:UIBarButtonItemStylePlain target:self action:@selector(populateDataSource)];
}
return self;
}
- (void)populateDataSource
{
NSMutableArray* new_rows = [[NSMutableArray alloc] init];
[((MyTableViewDataSource*)self.tableView.dataSource) setRowCount:200];
for (int i = 0; i < 200; i ++)
[new_rows addObject:[NSIndexPath indexPathForRow:i inSection:0]];
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:new_rows withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView.dataSource = [[MyTableViewDataSource alloc] init];
self.navigationItem.rightBarButtonItem = populateButtonItem;
}
@end
मेरा पहला अनुमान यह होगा कि आपकी टेबल सेल अपराधी हैं। क्या आप कस्टम सेल का उपयोग कर रहे हैं? – lyricsboy
क्या आप कुछ कोड पोस्ट कर सकते हैं? इसके अलावा: क्या आपके UITableViewCells अपारदर्शी हैं? – Ahti
आपके बाधाओं का संकेत देने वाले उपकरण क्या हैं? क्या आप उन्हें एक ही डिलीवरी के साथ बड़े पैमाने पर हटा रहे हैं RowsAtIndexPaths: ... कॉल, या कई व्यक्तिगत कॉल? क्या आप एनिमेशन के बीच में reloadData को कॉल कर रहे हैं (आपको ऐसा कभी नहीं करना चाहिए)? –