Dường như XCode 6 khác với việc sử dụng thẻ viewwithtags thì XCode 5 là.XCode 6 Chế độ xem UICollectionviewvới thẻ không hoạt động
Tôi đang sử dụng mã sau trong XCode 6 với Bảng phân cảnh. 50 ô được tạo nhưng nhãn không hiển thị. Mọi thứ được đặt chính xác như thẻ, v.v. Nếu tôi sử dụng cách XCode 5 "cũ" để làm điều đó với ô Đăng ký được phân loại, có vẻ như hoạt động cho iOS 7 nhưng trong iOS 8 dữ liệu không được chuyển đến nhãn cho đến khi tôi bắt đầu cuộn.
static NSString * const reuseIdentifier = @"MyCell";
- (void)viewDidLoad {
[super viewDidLoad];
// Register cell classes
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return 50;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
UILabel *nameLabel = (UILabel *)[cell viewWithTag:102];
nameLabel.text = @"Hello World";
nameLabel.textColor = [UIColor whiteColor];
cell.backgroundColor = [UIColor blueColor];
return cell;
}
Cập nhật câu trả lời vì thao tác này nhưng dưới iOS 8 ô đầu tiên sẽ không hiển thị nội dung. Chỉ sau khi cuộn lên và xuống nội dung đang tải lên nhãn.
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"Cell";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
UILabel *nameLabel = (UILabel *)[cell viewWithTag:102];
nameLabel.text = @"Hello World";
nameLabel.textColor = [UIColor whiteColor];
cell.backgroundColor = [UIColor blueColor];
return cell;
}
Ảnh chụp màn hình ở đây:
https://www.dropbox.com/s/xs6gbvz3d04e4hv/Bildschirmfoto%202014-09-21%20um%2023.08.18.png?dl=0 https://www.dropbox.com/s/tp67rznggi5pcwt/Bildschirmfoto%202014-09-21%20um%2023.10.06.png?dl=0
Bạn không nên đăng ký lớp học nếu ô được tạo trong bảng phân cảnh (dành cho iOS 7 hoặc 8). Nếu bạn đăng ký lớp, bạn sẽ nhận được ô cơ bản mặc định. – rdelmar
Cảm ơn. Tôi đã không đăng ký lớp học bây giờ nhưng vấn đề trong iOS 8 là nhãn không được cập nhật với nội dung khi collectionview được tải. Các ô bắt đầu cập nhật với nội dung khi tôi bắt đầu cuộn. – Ben
@Ben, bạn có tìm thấy giải pháp không? – Yerkezhan