如图:我在collection.xib中创建了2个cell,定义了不同的identifier,
使用的时候:
NSArray *nibArrays = [[UINib nibWithNibName:@"LongCell" bundle:nil] instantiateWithOwner:nil options:nil]; [collectionView registerClass:[[nibArrays objectAtIndex:0] class] forCellWithReuseIdentifier:@"LongCellFirst"]; [collectionView registerClass:[[nibArrays objectAtIndex:1] class] forCellWithReuseIdentifier:@"LongCellSecond"];
#pragma mark - UICollectionViewDelegate DataSource - - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.item % 2 == 0) { LongCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"LongCellFirst" forIndexPath:indexPath]; return cell; }else { LongCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"LongCellSecond" forIndexPath:indexPath]; return cell; } }
这样能运行,但是取出的cell都是上面什么也没有。
是我注册cell不对吗??还是因为不能这样用?tableViewCell.xib就可以这样搞啊?
tableView.xib中创建多个cell
请大神解释啊。。。。。。
You created it using nib, shouldn't you use registerNib to register it? Why use regClass.
The xib file was read incorrectly
NSArray *nibArrays=[[NSBundle mainBundle]loadNibNamed:@"LongCell" owner:nil options:nil];
Two methods:
split into two
xib
,每次registerNib:
one;Synthesize one, but initialize the instance yourself:
It is recommended that one xib file corresponds to one View, there is no need to save files
According to the method mentioned above, the cell can be displayed, but the control settings in the cell have no effect. Has the author solved the problem?
When associating the controls on the cell in the cell, if you don’t make any changes. All your associated controls default to controls on cell1. In layman's terms, when connecting, the controls on the first cell are used by default