2013-02-07 27 views
5

tôi đang tạo ứng dụng CollectionView. nơi tôi đang lấy dữ liệu từ máy chủ thông qua chuỗi JSON. và luồng công việc của tôi như sauSự cố trong bộ chọn không được nhận dạng được gửi đến ví dụ

  1. Bộ sưu tập đã tạo Xem ô như ProjectVCollectionViewCell.h, .m, .xib.

    Mã cho .h là -

@ interface ProjectCollectionViewCell: UICollectionViewCell
@property (yếu, nonatomic) IBOutlet UIImageView * projectImage;
@property (yếu, nonatomic) IBOutlet UILabel * projectLabel;
@end

Mã cho .m là mặc định và tổng hợp 2 biến trên. và .xib có Collection Xem di động với hình ảnh Xem và Label (Linked lớp trên với quan điểm thu tế bào và liên kết tên định danh là "projectCell".

  1. Mã cho ViewController của nó, chứa collectionView, là như sau

Mã bên trong cho ViewController.m là

- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section{ 
    return [projectList count]; 
} 
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath; 
{ 
    ProjectCollectionViewCell *cell = (ProjectCollectionViewCell *)[cv dequeueReusableCellWithReuseIdentifier:@"projectCell" forIndexPath:indexPath];  

    cell.projectLabel.text = @"";//Here i am getting issue 
    //cell.projectLabel.text = [[NSString alloc] initWithString:[[projectList objectAtIndex:indexPath.row] objectForKey:@"albumName"]];   
    return cell; 
} 

trong trên Mã cell.projectlabel được đem lại cho tôi phát hành

[UICollectionViewCell projectLabel]: unrecognized selector sent to instance 0x75f0fb0 
2013-02-07 20:08:17.723 Sample[3189:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UICollectionViewCell projectLabel]: unrecognized selector sent to instance 0x75f0fb0' 
*** First throw call stack: 

giá trị ô là tốt, tôi truy tìm điều đó với NSLog và gợi ý mã cũng lấy projectLabel sau ".". Nhưng tôi không thể đặt giá trị trường nhãn bằng cách này. Vui lòng giúp tôi ra ngoài.

+0

Bạn đã đăng ký ngòi? –

+0

Có. như dưới đây - [self.projectListView registerClass: [UICollectionViewCell class] forCellWithReuseIdentifier: @ "projectCell"]; – VarunJi

+0

@Sang Bạn là thiên tài. :). Bạn đã cứu cuộc đời tôi. Hãy làm điều này làm câu trả lời của bạn. Tôi sẽ coi đó là Solution. – VarunJi

Trả lời

2

Trong trường hợp tạo tùy chỉnh ProjectCollectionViewCell với ProjectCollectionViewCell.xib, bạn phải registerNib trong viewDidLoad:

[self.projectListView registerNib:[UINib nibWithNibName:@"ProjectCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"projectCell"]; 

Bạn nên thay đổi để sử dụng kịch bản cho tiết kiệm thời gian với CollectionView. Không cần phải đăng ký bất cứ điều gì, chỉ cần chọn customCell, kéo và thả mọi thứ bạn muốn vào ô CollectionView và kéo IBOutlet: https://github.com/lequysang/testCollectionViewScroll

Các vấn đề liên quan