您好我正在使用UICollectionView
来显示要在数组中输入的输入值。但是,问题是我在自定义customCell
中使用了UICollectionView
UITableViewCell
。它有滚动UITableView
的时间,更改的项目数和未正确显示的项目数的问题。我尝试过很少的第三方课程,例如AFTabledCollectionView
和HorizontalCollectionView
。请帮帮我
//View Controller Class
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return ar.count;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"cell";
CustomCells *cell = (CustomCells *)\[tableView dequeueReusableCellWithIdentifier:cellIdentifier\];
;
if (cell == nil) {
cell = [[CustomCells alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"\];
}
cell.lbl.text = @"Test";
cell.textLabel.textColor=[UIColor whiteColor];
[[NSUserDefaults standardUserDefaults] setInteger:[[self.array objectAtIndex:indexPath.row]count] forKey:@"r"];
cell.routelbl.text=[NSString stringWithFormat:@"Route %d",(int)indexPath.row+1];
// ... set up the cell here ...
cell.layer.cornerRadius=5;
cell.layer.masksToBounds=YES;
return cell;
}
// Custom TableViewCell
- (void)awakeFromNib {
[self.collectionview reloadData];
ViewController *v=[[ViewController alloc] init];
NSLog(@"temp %d %d ",temp,v.array.count);
f=[NSUserDefaults standardUserDefaults];
temp=(int)[f integerForKey:@"r"];
ar=[[NSMutableArray alloc] init];
[ar addObject:@"3"];
[ar addObject:@"4"];
[ar addObject:@"2"];
[ar addObject:@"1"];
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
flowLayout.itemSize = CGSizeMake(70, 91.0);
// \[self.collectionview setCollectionViewLayout:flowLayout\];
[self.collectionview registerNib:[UINib nibWithNibName:@"CustomCollectionViewCells" bundle:nil] forCellWithReuseIdentifier:@"cvCell2"];
self.collectionview.layer.cornerRadius=5;
self.collectionview.layer.masksToBounds=YES;
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated\];
// Configure the view for the selected state
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
NSLog(@"temp %d mm ",temp);
return temp;
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
return 1;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
temp=(int)indexPath.row;
CustomCollectionViewCells *cell = (CustomCollectionViewCells *)\[collectionView dequeueReusableCellWithReuseIdentifier:@"cvCell2" forIndexPath:indexPath\];
cell.layer.cornerRadius=5;
cell.layer.masksToBounds=YES;
return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
NSLog(@"%d",(int)indexPath.row);
}
我面临的问题是使UICollectionView
动态和离散的项目数量,以及构造数组。即添加新的UITableViewCell
和UICollectionViewCell
添加和删除。
答案 0 :(得分:0)
当表中的行数设置为1并且一行中的节数设置为NSArray的计数
时,UITableView中的UICollectionView工作正常