我在这里没有找到任何好的资源,所以我认为把它放在外面会很棒......并阻止我把头发拉出来。
就像应用程序“议程”(日历应用程序)一样 - 我有一个表格视图,每个单元格代表一天。下一步是将 eventsArray 放置在适当的单元格内 - 通过 cellForRowAtIndexPath。
我只熟悉显示带有部分和行的 eventsArray - 使用每个 indexPath 来表示一个事件......而不是一个事件数组。(下面我为其他在该部门寻求帮助的人发布了工作代码,并作为参考)。
如果有人可以在单个单元格中放置一些代码来执行 eventsArray,那就太好了——我假设这是对我不熟悉的 cellForRowAtIndexPath 的使用。先感谢您。有什么问题就拍。
{
#pragma mark - TableView stuff
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
A1Section *a1section = [self.sections objectAtIndex:section];
return [a1section.rows count];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [self.sections count];
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
A1Section *a1section = [self.sections objectAtIndex:section];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"EEEE, MMM d, yyyy"];
NSString *myDateString = [formatter stringFromDate:a1section.date];
return [NSString stringWithFormat:@"%@", myDateString];
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 47;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 75;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UILabel *timeLabel = nil;
UILabel *nameLabel = nil;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.backgroundColor = [UIColor redColor];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(11.0, 13.0, 55.0, 15.0)];
[timeLabel setTag:1];
[timeLabel setBackgroundColor:[UIColor clearColor]];
timeLabel.textAlignment = UITextAlignmentLeft;
[timeLabel setFont:[UIFont fontWithName:@"HelveticaNeue-Bold" size:14]];
[timeLabel setTextColor:[UIColor blackColor]];
[timeLabel setLineBreakMode:NSLineBreakByClipping];
[timeLabel setNumberOfLines:1];
[cell.contentView addSubview:timeLabel];
nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(85.0, 11.0, 200.0, 20.0)]; //x = 80.0, width = 235
[nameLabel setTag:2];
[nameLabel setBackgroundColor:[UIColor clearColor]];
nameLabel.textAlignment = UITextAlignmentLeft;
[nameLabel setFont:[UIFont fontWithName:@"HelveticaNeue-Bold" size:17]];
[nameLabel setTextColor:[UIColor blackColor]];
[nameLabel setLineBreakMode:NSLineBreakByTruncatingTail];
[nameLabel setNumberOfLines:1];
[cell.contentView addSubview:nameLabel];
} else {
timeLabel = (UILabel *)[cell.contentView viewWithTag:1];
nameLabel = (UILabel *)[cell.contentView viewWithTag:2];
}
A1Section *a1section = [self.sections objectAtIndex:indexPath.section];
PFObject *object = [a1section.rows objectAtIndex:indexPath.row];
NSDate *someDate = [object objectForKey:@"startDate"];
NSString *time = [self.dateFormatter stringFromDate:someDate];
[(UILabel *)[cell.contentView viewWithTag:1] setText:time];
[(UILabel *)[cell.contentView viewWithTag:2] setText:[object objectForKey:@"textContent"]];
return cell;
}
}