-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;
}

请帮我。

4

4 回答 4

1

我认为您是新的 Iphone 开发人员 .. 在您的代码中有很多错误/Bug ...

我想你想要

“如何创建自定义单元格”`请参考此链接....为您提供帮助

于 2012-04-25T13:30:17.360 回答
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:)

于 2012-04-25T13:46:26.440 回答
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 设置并与情节提要中的单元格相关联。然后,您需要在自定义单元格中设置所需的三个标签(标题、postedBy、onDate),以便将数据插入标签中。

本教程可能会对您有所帮助:http: //ijoshsmith.com/2011/07/16/creating-a-custom-uitableviewcell-in-ios-4/

于 2012-04-25T14:33:20.093 回答
0

您可以使用:

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

如果您不想创建自定义 UITableViewCell 类。

于 2012-04-25T15:34:11.787 回答