繁体   English   中英

如何在Objective C中的TableView中调用CollectionView的委托方法?

[英]How to call delegate methods of CollectionView inside TableView in Objective C?

TableViewCell类

- (void)awakeFromNib {
 //Registering CollectionViewCell
}


- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return [productsData count];
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionCell" forIndexPath:indexPath];
    NSDictionary *cellData = [productsData objectAtIndex:[indexPath row]];
    cell.imageView.image = [UIImage imageNamed:[cellData objectForKey:@"image"]];
    return cell;
}

如何调用集合视图的委托方法?

在您的TableViewCell.h文件中添加。

@property (nonatomic, assign) UICollectionView *yourCollectionView;

在您的TableViewCell.m文件中添加。

@synthesize yourCollectionView;

在您的init方法中,分配集合视图并设置委托和数据源。

yourCollectionView = [UICollectionView alloc] initWithFrame://( your frame) ];

yourCollectionView.dataSource = self;
yourCollectionView.delegate = self;
// set other properties as per tour needs .

[self.contentView addSubview:yourCollectionView];

添加检查您的委托方法的方法。 希望对您有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM