2016-01-15 7 views
6

मैं एक UITableViewCell में एक UICollectionView है। तो पदानुक्रम इस तरह है:UICollectionView में स्क्रॉल और उसका आकार बदलने सभी कोशिकाओं रैप करने के लिए अक्षम

UITableView -> UITableViewCell -> UICollectionView -> UICollectionViewCell

क्या मैं यहाँ हासिल करना चाहते हैं UICollectionView में अक्षम स्क्रॉल है, और यह एक बड़ी सूची की तरह लग रहे बनाने के वस्तुओं का सभी सामग्री गतिशील रूप से बनाई गई हैं। तो मैं अपनी कोशिकाओं के आधार पर UICollectionView का आकार कैसे बदलूं। इसकी ऊंचाई कुल UICollectionViewCells के बराबर होनी चाहिए।

धन्यवाद!

संपादित करें: मैं स्क्रॉल को निष्क्रिय करने में कामयाब रहे हैं और यह काम किया। फिर सेल का आकार बदलने की कोशिश की लेकिन यह कुछ भी प्रतीत नहीं होता है:

cell.viewscollectionview.scrollEnabled = false 
cell.viewscollectionview.frame = CGRectMake(0, 0, tableView.frame.width, 800) 
+0

(कम से [इस ट्यूटोरियल] एक नज़र http://www.raywenderlich.com/87975/dynamic-table-view-cell- ले लो ऊंचाई-आईओएस -8-स्विफ्ट), आपकी मदद कर सकता है। आप दो गतिशील ऊंचाइयों होने पहुंच जाएंगे: 1) 'UICollectionView' की ऊंचाई' अपनी ऊंचाइयों के UICollectionViewCells' x संख्या के आधार पर; 2) 'UITableViewCell' की ऊंचाई होना चाहिए के बराबर होती है' UICollectionView' के एक बार यह यह ऊंचाई है अपडेट किया गया है। – mathielo

+0

तो मैं कैसे UIcollectionView की ऊंचाई कोई बात नहीं मैं क्या कर बदल सकता हूँ, यह स्टोरीबोर्ड में एक सेट के रूप में ही रहता है। –

+0

क्या स्टोरीबोर्ड में इसकी कोई बाधा है? – lukasbalaz7

उत्तर

1

ऑटोलाउट्स का उपयोग करने का प्रयास करें। संग्रह दृश्य ऊंचाई यह beginning.Later में लगातार constraint.Keep का प्रयोग करें आप सेल में डेटा जोड़ने के रूप में ऊंचाई बाधा के लगातार बदल कर संग्रह को देखने की ऊंचाई को समायोजित।

1

आपको तालिका दृश्य प्रतिनिधि में heightForRowAt के अंदर UICollectionView ऊंचाई की गणना करनी होगी।

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 

    // constants, should be initialized somewhere else 
    let totalItem: CGFloat = 20 
    let totalCellInARow: CGFloat = 3 
    let cellHeight: CGFloat = 120 

    let collViewTopOffset: CGFloat = 10 
    let collViewBottomOffset: CGFloat = 10 

    let minLineSpacing: CGFloat = 5 

    // calculations 
    let totalRow = ceil(totalItem/totalCellInARow) 
    let totalTopBottomOffset = collViewTopOffset + collViewBottomOffset 
    let totalSpacing = CGFloat(totalRow - 1) * minLineSpacing // total line space in UICollectionView is (totalRow - 1) 
    let totalHeight = (itemHeight * totalRow) + totalTopBottomOffset + totalSpacing 

    return totalHeight 
} 

पूर्ण ट्यूटोरियल के लिए, आप इसे यहाँ पढ़ सकते हैं: https://medium.com/@adinugroho/fixed-height-uicollectionview-inside-uitableview-79f24657d08f

संबंधित मुद्दे