Chức năng của reuseIdentifier trong iOS là gì?
Chức năng của reuseIdentifier trong iOS là gì?
reuseIdentifier là chuỗi định danh cho tái sử dụng cell (UITableViewCell/ UICollectionViewCell) — thay vì tạo cell mới cho mỗi hàng, UIKit lấy lại cell đã cuộn ra khỏi màn hình → tiết kiệm bộ nhớ và mượt.
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)ip {
UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:@"UserCell" forIndexPath:ip]; // lấy cell tái sử dụng (đã register)
cell.textLabel.text = self.users[ip.row].name; // CẬP NHẬT lại mọi trạng thái!
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.