我正在从 URL 解析一些数据,并且能够正确检索数据。现在我想在自定义表格视图中显示该数据,但我无法将数据显示到表格中。这是我的代码
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [url count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
UILabel *LBtitle = [[UILabel alloc]initWithFrame:CGRectMake(60, 5, 250, 40)];
LBtitle.font = [UIFont boldSystemFontOfSize:13.0];
LBtitle.numberOfLines=2;
[LBtitle sizeToFit];
UILabel *LBurl = [[UILabel alloc]initWithFrame:CGRectMake(60, 45, 250, 20)];
LBurl.font = [UIFont systemFontOfSize:13.0];
LBurl.textColor = [UIColor blueColor];
LBurl.numberOfLines=1;
[LBurl sizeToFit];
UILabel *LBcontent = [[UILabel alloc]initWithFrame:CGRectMake(60, 65, 250, 60)];
LBcontent.font = [UIFont systemFontOfSize:13.0];
LBcontent.textColor = [UIColor grayColor];
LBcontent.numberOfLines=3;
[LBcontent sizeToFit];
LBtitle.text = [titleNoFormatting objectAtIndex:indexPath.row];
LBurl.text = [url objectAtIndex:indexPath.row];
LBcontent.text = [content objectAtIndex:indexPath.row];
[cell.contentView addSubview:LBtitle];
[cell.contentView addSubview:LBurl];
[cell.contentView addSubview:LBcontent];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
//cell.textLabel.text = [titleNoFormatting objectAtIndex:indexPath.row];
//cell.detailTextLabel.text = [url objectAtIndex:indexPath.row];
// Configure the cell...
if (indexPath.row % 2 == 0) {
cell.backgroundColor = [UIColor whiteColor];
}
else{
cell.backgroundColor = [UIColor colorWithRed:231/255.0 green:227/255.0 blue:227/255.0 alpha:1.0];
}
return cell;
}
如果我写cell.textlabel.text = [titleNoFormatting objectAtIndex:indexPath.row];
比数据显示在表中。