Một UIViewController duy trì một tham chiếu đến một UICollectionView. Bộ điều khiển nên sửa đổi bố cục luồng tích hợp bằng cách sử dụng UICollectionViewDelegateFlowLayout.Cách đặt UICollectionViewDelegateFlowLayout?
Đó là khá dễ dàng để thiết lập của xem nguồn dữ liệu để tự:
MyViewController.m
- (void)viewDidLoad
{
self.collectionView.dataSource = self;
}
Nhưng làm cách nào để thiết lập bộ điều khiển được bố trí dòng chảy đại biểu về quan điểm?
- (void)viewDidLoad
{
self.collectionView.dataSource= self;
// self.collectionView.??? = self;
}
Tôi đã thử:
- (void)viewDidLoad
{
self.collectionView.dataSource= self;
self.collectionView.collectionViewLayout = self;
}
Nhưng tôi nhận được lỗi: "loại con trỏ không tương thích giao ...".
Bộ sưu tập file header trông như thế này:
MyViewController.h
@interface MyViewController : UIViewController <UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
@JohnEstropia, xin lỗi, nhưng làm cách nào để init bố cục tùy chỉnh trong mã? Tôi thấy các ví dụ với bảng phân cảnh nhưng không phải với chính mã. Tôi nên làm gì? – gaussblurinc
có thể, 'self.collectionViewLayout = UICollectionViewFlowLayout()', 'self.collectionViewLayout = [[UICollectionViewFlowLayout alloc] init]' –