Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> iOS

วิธีสร้าง NSIndexPath สำหรับ TableView ใน iOS

Index Path เป็นชุดค่าสองตัวแทน row และ section ของ TableView สร้างได้ทั้ง Objective-C และ Swift

Objective-C

NSIndexPath *myIP = [NSIndexPath indexPathForRow:5 inSection:2];

Swift

IndexPath(row: 2, section: 4)

การใช้งานใน cellForRowAt

let cell = tblView.cellForRow(at: IndexPath(row: 5, section: 2))

ทั้งสองวิธีใช้สร้าง index path เพื่อเข้าถึง cell หรือข้อมูลใน table view ได้อย่างแม่นยำ