我已经构建了一个 UITableView,其中包含从动态数组提供的自定义单元格。
我的数组代码在这里 -
feedData *feedData1 = [[feedData alloc] initWithFeedTitle:@"Fishing Article" FeedGroup:@"articleP" FeedImage:@"blah" FeedDate:@"1/11/13" FeedDesc:@"Check out this swimming article..." FeedDestination:@"articlesSub" ];
feedData *feedData2 = [[feedData alloc] initWithFeedTitle:@"Runnung Article" FeedGroup:@"articleP" FeedImage:@"blah" FeedDate:@"4/11/13" FeedDesc:@"Check out this marvellous article..." FeedDestination:@"articlesSub" ];
feedData *feedData3 = [[feedData alloc] initWithFeedTitle:@"Runnung Article" FeedGroup:@"articleP" FeedImage:@"" FeedDate:@"4/11/13" FeedDesc:@"Check out this marvellous article..." FeedDestination:@"articlesSub" ];
self.HpFeedArray = [NSArray arrayWithObjects:feedData1, feedData2, feedData3, nil];
我想要每个单元格上方的边距 - 我能想到如何做到这一点的唯一方法是将单元格分成多个部分,应用部分标题并在每个部分中显示一行 - 我当前的代码是这样的 -
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.HpFeedArray.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 10.; // you can have your own choice, of course
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *headerView = [[UIView alloc] init];
headerView.backgroundColor = [UIColor clearColor];
return headerView;
}
然后我将相关数据应用于相关单元格,如下所示 -
-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier =@"CellFeed";
feedData *f = [self.HpFeedArray objectAtIndex:indexPath.row];
tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
UITableViewCell *cell;
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
CellHp_RecArticleWithImage *CellArticle = (CellHp_RecArticleWithImage *)cell;
CellArticle.selectionStyle = UITableViewCellSelectionStyleNone;
CellArticle.artTitle.text = f.FeedTitle;
CellArticle.artImg.text = f.FeedDesc;
CellArticle.artDate.text = f.FeedDate;
CellArticle.textLabel.backgroundColor=[UIColor clearColor];
return CellArticle;
上面显示了间隔开的单元格 - 但显示相同的数据 3 次!谁能帮我弄清楚我做错了什么!?
干杯保罗