假数据自我添加测试--NSArray object

时间:2024-09-17 20:33:38
一、列表假数据
//在.h文件里面定义node所包含实体类---1
struct listTestNode
{
NSString *image;
NSString *name;
};
//在.m实现文件里面
//把不同的数据赋值给NSArray---------2
NSArray *testList = [[NSMutableArray alloc]init];
for(int i=0;i<3;i++)
{
struct listTestNode node;
switch (i)
{
case 0:
{
node.name = @"name1";
node.image = [[NSString alloc]initWithFormat:@"人%d.jpg",i]; }
break;
case 1:
{
node.name = @"name2";
node.image = [[NSString alloc]initWithFormat:@"人%d.jpg",i];
}
break;
case 2:
{
node.name = @"name3";
node.image = [[NSString alloc]initWithFormat:@"人%d.jpg",i];
}
break; default:
break;
} [testList addObject:[NSValue valueWithBytes:&node objCType:@encode(struct listTestNode)]];
}
//最后再tableView里面引用NSArray-------3
struct listTestNode node;
[[testList objectAtIndex:indexPath.row]getValue:&node];
二、单个假数据添加应用(以图片为例)
//给NSAray赋值,让他包含他的objects-------1
NSArray *testImages = [[NSArray alloc] initWithObjects: @"1.jpg", @"2.jpg", @"3.jpg",@"4.jpg",nil];
//在tableView里面引用NSAray-------------2
UIImageView *imageView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:fileName]];
fileName=[testImages objectAtIndex:[indexPath row]];