0

我尝试从包含自定义对象的 NSMutableArray 填充 UITable 失败。

我的学生对象

Student {
    NSString name,
    int age
}

在我的 UITableView 的控制器中,我实现了一个显示行内容的方法:

cellForRowAtIndexPath
{
    // there is more code here
    cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
}

但以上不适用于数组内的对象。

我的学生类是否应该实现一个返回对象的字符串表示形式的方法?然后如何在 UITableView 中显示 NSMutableArray 的内容。

任何帮助将不胜感激。

4

1 回答 1

0

您的 objectAtIndex 应该是 Student 对象,因此您需要获取它的属性——假设 name 和 age 是属性,您应该能够使用 [(Student *)[tableData objectAtIndex:indexPath.row] name]; 引用它们 和相应的年龄。

于 2012-04-29T00:10:57.640 回答