【发布时间】:2023-03-24 20:01:01
【问题描述】:
我是 Objective-c 的新手。我正在处理集合视图。在我的集合视图中,我的数组中有数据列表。当我将数组中的数据加载到集合单元格时,它没有按照数组顺序显示。当我滚动时,单元格值不断变化。
这是我的代码。
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return myObject.count;
}
- (UIView *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CELL" forIndexPath:indexPath];
if([statusfield isEqualToString:@"13"])
{
[cell.mySegmentedControl setTitle:@"SEND TO ADMIN" forSegmentAtIndex:0];
[cell.mySegmentedControl setTitle:@"EVALUATE" forSegmentAtIndex:1];
}
else if([statusfield isEqualToString:@"5"])
{
[cell.mySegmentedControl setEnabled:NO forSegmentAtIndex:0];
[cell.mySegmentedControl setEnabled:NO forSegmentAtIndex:1];
}
else if([statusfield isEqualToString: @"1"])
{
[cell.mySegmentedControl setTitle:@"ACCEPT" forSegmentAtIndex:0];
[cell.mySegmentedControl setTitle:@"REJECT" forSegmentAtIndex:1];
}
else if([statusfield isEqualToString:@"3"])
{
[cell.mySegmentedControl setTitle:@"VIEW" forSegmentAtIndex:0];
[cell.mySegmentedControl setSelectedSegmentIndex:UISegmentedControlNoSegment];
}
return cell;
}
分段控件值正在根据数组更新。当我滚动集合视图时,顺序正在改变。任何帮助将不胜感激。
【问题讨论】:
-
这是由于 cell 的可重用性而发生的。您可以使用 Model 类对其进行管理。
-
你能给我的场景一个例子或示例程序吗...
标签: ios objective-c uicollectionview nsarray uicollectionviewcell