- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return departureTimesArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
User *user = [departureTimesArray objectAtIndex:indexPath.row];
UILabel *label = (UILabel*)[cell.contentView viewWithTag:100];
if (!label)
{
label = [[UILabel alloc] initWithFrame:CGRectMake(12.0, 90.0,90.0, 30.0)];
label.textColor = [UIColor redColor];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:16];
label.textColor = [UIColor colorWithRed:46.0/255.0 green:63.0/255.0 blue:81.0/255.0 alpha:1.0];
label.tag = 100;
[cell.contentView addSubview:label];
}
// label.text=user.departureTime_Bus;
label.text = [NSString stringWithFormat:@"%@",user.departureTime_Bus];
return cell;
}
自定义委托方法
-(void)repaint:(NSMutableArray *)retrievedData
{
if (retrievedData.count > 0)
{
NSLog(@"%@is the value",retrievedData);
userObj = [retrievedData objectAtIndex:0];
[departureTimesArray addObjectsFromArray:retrievedData];
[mycollectionView reloadItemsAtIndexPaths:departureTimesArray];
}
}
答案 0 :(得分:1)
首先检查
@interface ViewController : UIViewController "<"UICollectionViewDelegate,UICollectionViewDataSource">"
第二件事是检查IBoutlet
@property (nonatomic, strong) IBOutlet UICollectionView *collectionView;
第三个是检查
self.collectionView.delegate=self;
self.collectionView.dataSource=self;
这三步必须调用集合视图的数据源和委托方法。
答案 1 :(得分:0)
如果数据源或委托方法没有触发,它通常是以下几种方法之一: