- (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];
}
}发布于 2014-08-11 16:05:06
如果数据源或委托方法没有触发,这通常是少数几件事情之一:
发布于 2016-10-12 12:03:25
先查一下这个
@interface ViewController : UIViewController "<"UICollectionViewDelegate,UICollectionViewDataSource">"第二件事是检查IBoutlet
@property (nonatomic, strong) IBOutlet UICollectionView *collectionView;第三种是检查
self.collectionView.delegate=self;
self.collectionView.dataSource=self;这三个步骤必须调用数据源和集合视图的委托方法。
https://stackoverflow.com/questions/25237801
复制相似问题