मैं एक ऐसी ही समस्या का सामना करना पड़ा है, और मैं एक नहीं बल्कि hackish-महसूस तरीके से हल किया है, लेकिन यह काम करता है, और मैं अब के लिए इसके साथ सामग्री हूँ।
असल में मैंने जो करने का फैसला किया था वह संग्रह दृश्य पृष्ठों को खाली UICollectionViewCells के साथ पैड करना था।
मैं पहली बार गणना करता हूं कि कितने कुल आइटम होंगे। यदि मेरे NSFetchedResultsController द्वारा प्रदान की गई वस्तुओं की कुल संख्या तीन में से एक सटीक नहीं है, तो मैं आवश्यक वस्तुओं को जोड़ता हूं ताकि कुल तीन में से एक हो।
#define ITEMS_PER_PAGE 3
//...
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
NSArray *sections = [categoriesFetchedResultsController sections];
id <NSFetchedResultsSectionInfo> sectionInfo = sections[section];
NSInteger categoryCount = [sectionInfo numberOfObjects];
NSInteger extraItemsNeeded = ITEMS_PER_PAGE - (categoryCount % ITEMS_PER_PAGE);
NSInteger totalItems = categoryCount + extraItemsNeeded;
NSInteger pages = (NSInteger)(totalItems/ITEMS_PER_PAGE);
self.pageControl.numberOfPages = pages;
return totalItems;
}
फिर जब यह समय कोशिकाओं को उत्पन्न करने आता है, मुझे क्या करना:
उदाहरण के लिए, अगर मैं चार श्रेणियों वापस पाने, मैं दो और अधिक जोड़ने के यह छह के कुल बनाने की आवश्यकता होगी निम्नलिखित:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
CategoryCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CategoryCell" forIndexPath:indexPath];
// use a generic UICollectionCell for the "empty cell" case.
UICollectionViewCell *emptyCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"EmptyCell" forIndexPath:indexPath];
if (indexPath.row < [[categoriesFetchedResultsController fetchedObjects] count]) {
NSManagedObject *object = [categoriesFetchedResultsController objectAtIndexPath:indexPath];
NSData *imageData = [object valueForKey:@"thumbnail_data"];
NSString *name = [object valueForKey:@"category_name"];
cell.image.image = [UIImage imageWithData:imageData];
cell.label.text = name;
return cell;
}
return emptyCell;
}
मुझे आशा है कि यह भविष्य में किसी को मदद करता है, के बाद से इस समस्या को हल करने के रूप में यह किया जाना चाहिए था के रूप में सरल नहीं था, और मैं हैरान हूँ कि प्रवाह लेआउट सिर्फ स्वचालित रूप से उचित रूप से पृष्ठों की गणना नहीं किया।
स्रोत
2013-02-08 06:53:23
क्या आप इस समस्या को हल करने में सक्षम थे? मुझे एक ही समस्या है। मेरे पास कुल 4 आइटम हैं, और प्रत्येक पृष्ठ में प्रत्येक तीन आइटम होना चाहिए। पहला पृष्ठ ठीक से बनाया गया है, लेकिन दूसरी पृष्ठ चौड़ाई स्पष्ट रूप से चौथी वस्तु के रूप में चौड़ी है, इसलिए यह वास्तव में पृष्ठ को दूसरे पृष्ठ पर कभी नहीं लगता है ... दूसरा "पृष्ठ" में दूसरा, तीसरा और चौथा आइटम होता है और यह वापस snaps। इसके बजाय, यह उम्मीद है कि यह पेज दो पर केवल एक आइटम होगा। किसी भी तरह की सहायता को आभार समझेंगे! –