我在填充表时遇到问题。
我创建了一个自定义视图,在视图中我创建了一个tableview。下面给出了UIView
子类的代码。出现该表并调用所有代理。
根据代理创建24个单元格并显示它们但不显示文本或任何其他单元格内容。我无法更改任何单元格属性,包括单元格背景颜色。
- (id)initWithFrame:(CGRect)frame andCellHeight:(CGFloat)cellh{
self = [super initWithFrame:frame];
if(self){
[self initTimeArray];
[self initTable];
}
return self;
}
- (void) initTable{
timeLine = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width,self.frame.size.height )];
timeLine.backgroundColor = [ UIColor clearColor];
timeLine.separatorStyle = UITableViewCellSeparatorStyleNone;
timeLine.rowHeight = cellHeight;
timeLine.delegate =self;
timeLine.dataSource = self;
[self addSubview:timeLine];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *simpleTableIdentifier = @"TimeCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
[cell setBackgroundColor:[UIColor blueColor]];
}
UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 28, 2)];
[lineView setBackgroundColor:[UIColor grayColor]];
// [cell.contentView addSubview:lineView];
UILabel *time = [[UILabel alloc]initWithFrame:CGRectMake(0, 10, 40 , 40)];
time.text = @"Test text";
time.textColor = [ UIColor redColor];
cell.textLabel.text = @"Another test Text";
[time setFont:[UIFont systemFontOfSize:14]];
[cell.contentView addSubview:time];
return cell;
}
-(void) initTimeArray
{
timeArray = [NSArray arrayWithObjects:@"12 PM", @"11 PM" ,
@"10 PM", @"9 PM", @"8 PM" , @"7 PM" ,
@"6 PM", @"5 PM", @"4 PM" , @"3 PM" ,
@"2 PM", @"1 PM", @"12 PM", @"11 AM" ,
@"10 AM", @"9 AM", @"8 AM" , @"7 AM" ,
@"6 AM", @"5 AM", @"4 AM" , @"3 AM",
@"2 AM", @"1 AM" , @"12 AM", nil];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 24;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}