2012-04-25 170 views
-1

我想在表格视图单元格中显示数据,我如何完成此操作。请帮我如何在表格视图单元格中显示数据

-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    static NSString *feedsTableIdentifier = @"FeedsTableIdentifier"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:feedsTableIdentifier]; 
    if (cell==nil) { 
     [[NSBundle mainBundle] loadNibNamed:@"FeedsTableViewCell" owner:self options:nil]; 
     cell=tableViewCell; 
     self.tableViewCell=nil; 
    } 
    title=(UILabel *)[cell viewWithTag:1]; 
    title.text=[NSString stringWithFormat:@"%d",indexPath.row]; 

    postedBy=(UILabel*)[cell viewWithTag:2]; 
    postedBy.text=[NSString stringWithFormat:@"%d",indexPath.row]; 

    onDate = (UILabel *)[cell viewWithTag:3]; 
    onDate.text=[NSString stringWithFormat:@"%d",indexPath.row]; 

    return cell; 
} 

请帮帮我。

+1

你是什么意思显示数据? – 2012-04-25 13:22:07

+0

你想要什么..这是你的代码,或者你只是举了例子来显示你想要显示的这种类型的数据 – Hiren 2012-04-25 13:35:59

+0

我想设置title,postingby和ondate的值。这些是tableviewcell上的标签 – Pradeep 2012-04-25 13:36:44

回答

0

除了阅读本:http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/TableView_iPhone/TableViewCells/TableViewCells.html#//apple_ref/doc/uid/TP40007451-CH7

尝试研究界面构建器/故事板如何帮助您,设置IBOutlets而不是使用[cell viewWithTag:3]尝试访问它们。使用IBOutlets你可以参考他们的名字,如:

postedByLabel.text = @"Some user"; 
titleLabel.text = @"A title!"; 

现在的日期你更好的了解NSDateNSDateFormatter :)

0

您正在寻找这样的事情:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    CellController *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
    cell = [[CellController alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 
    cell.menuLabel.text = [self.homeList objectAtIndex:indexPath.row]; 

    // Configure the cell... 

    return cell; 
} 

您需要有一个自定义的CellController设置并与故事板中的单元格关联。然后您需要在自定义单元格中设置所需的三个标签(title,postingBy,onDate),以便将数据插入到标签中。

本教程可以帮助你:http://ijoshsmith.com/2011/07/16/creating-a-custom-uitableviewcell-in-ios-4/

0

您可以使用:

cell.textLabel.text = @"Some text"; 

如果你不想创建一个自定义的UITableViewCell类。

相关问题