我想在一个视图控制器中放置多个 uicollectionview 我已成功将其放入情节提要中,并且我在 .m 文件中也有代码,如下所示。
-(UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath: (NSIndexPath *)indexPath;
{
if (_collectionview.tag==2) {
Cell *cell = [cv dequeueReusableCellWithReuseIdentifier:kCellID forIndexPath:indexPath];
[cell.image setImageWithURL:[NSURL URLWithString:@"http://192.168.0.104:808/Images/Image1.jpg"]placeholderImage:[UIImage imageNamed:@"0.jpg"]];
cell.label.text = [[recipes valueForKey:@"name"]objectAtIndex:0];
return cell;
}
if(_collectionview.tag==1)
{
Cell *cell = [cv dequeueReusableCellWithReuseIdentifier:jerryCellID forIndexPath:indexPath];
[cell.image1 setImageWithURL:[NSURL URLWithString:@"http://img1.wikia.nocookie.net/__cb20121123214954/tomandjerry/images/a/a8/Jerry_(3).jpg"]placeholderImage:[UIImage imageNamed:@"0.jpg"]];
cell.catlabel.text = [[recipes valueForKey:@"name"]objectAtIndex:0];
return cell;
}
else
{
Cell *cell = [cv dequeueReusableCellWithReuseIdentifier:kCellID forIndexPath:indexPath];
[cell.image setImageWithURL:[NSURL URLWithString:@"https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcT4RNUL18GXdQt2h9Ay4e7eHwm1lgC1BiRKrZY72Apt7b9cTViR7Q"]placeholderImage:[UIImage imageNamed:@"0.jpg"]];
cell.label.text = [[recipes valueForKey:@"name"]objectAtIndex:0];
return cell;
} }
上面的代码正在运行,但它仅适用于一个集合视图,我使用断点对其进行了调试,因此它进入第一个返回语句。所以另一部分代码甚至没有运行。那么如何解决这个问题。先感谢您 :)