2016-08-18 8 views
8

पर स्क्रॉल किया गया है, क्या निम्न पोस्ट अभी भी पता लगाने का स्वीकार्य तरीका है जब UITableView का एक उदाहरण [स्विफ्ट में] नीचे स्क्रॉल किया गया है, या इसे बदल दिया गया है (जैसा कि: बेहतर है)?पता लगाएं कि UITableView नीचे

Problem detecting if UITableView has scrolled to the bottom

धन्यवाद।

उत्तर

23

इस

func scrollViewDidScroll(_ scrollView: UIScrollView) { 
    let height = scrollView.frame.size.height 
    let contentYoffset = scrollView.contentOffset.y 
    let distanceFromBottom = scrollView.contentSize.height - contentYoffset 
    if distanceFromBottom < height { 
     print(" you reached end of the table") 
    } 
} 

प्रयास करें या आप इस तरह से

if tableView.contentOffset.y >= (tableView.contentSize.height - tableView.frame.size.height) { 

     //you reached end of the table 
    } 
+3

धन्यवाद @ Anbu.Karthik में पा सकते हैं। मैं अच्छा कर सकता हूँ मैं * अपमानित हूं * 2016 में इस तरह के आदिम तरीकों का उपयोग अभी भी किया जाना चाहिए, लेकिन ऐसा ही हो। इंजीनियरों को "func scrollViewDidScrollToBottom" फ़ंक्शन पेश करने से रोक रहा है? –

+0

@TheMotherofJosephBeuys - मैं अपनी बात नहीं मिल रहा है, वहाँ कोई भी तरीका आईओएस 'समारोह scrollViewDidScrollToBottom" ' –

+0

में उपलब्ध चिंता मत करो @ Anbu.Karthik है, मैं सिर्फ कराह रही हूँ –

16

स्विफ्ट 3

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { 
    if indexPath.row + 1 == yourArray.count { 
     print("do something") 
    } 
} 
+1

यह समाधान केवल 1 खंड होने पर मान्य है। जब अधिक अनुभाग हैं , तो बाएं हाथ की पंक्तियों को जमा करने की आवश्यकता है। – kjoelbro

+1

यह मेरे लिए सबसे अच्छा जवाब है –

+1

@kjoelbro आपको पूरी 'इंडेक्सपाथ' आसान मिल गई है। आप आसानी से निर्धारित कर सकते हैं कि आपके टेबलव्यू का अंत कहां है –

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