![](/img/trans.png)
[英]How can I call UITextField delegate methods in a different Objective-C class?
[英]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.