【发布时间】:2013-03-07 16:56:22
【问题描述】:
我的 ViewController 中有一个表,在这个表中我会从 webService 和 CoreData 中获取一些信息,这些信息来自每一行,当我在每一行中按下时,我想去详细视图并创建图像,
我有卡片,每张卡片上都有不同的印章,当我要查看详细信息时,我想创建这些图像,我的意思是如果我的卡有 2 个印章我想创建 2 个图像,如果我想创建 3 个印章创建 3 张图片,
你能帮我完成这个实现吗? 提前致谢!
这是我从网络服务获得的信息:
createdAt = 1362412409;
id = 2;
stampNumber = 2;
},
{
createdAt = 1362069567;
id = 1;
stampNumber = 10;
}
这是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath
{
static NSString *CellIdentifier = @"CardsCell";
CardCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil){
NSArray *objects = [[NSBundle mainBundle] loadNibNamed:@"CardCell" owner:nil
options:nil];
for (id currentObject in objects)
{
if([currentObject isKindOfClass:[UITableViewCell class]])
{
cell = (CardCell *) currentObject;
break;
}
}
}
card = self.cards[indexPath.row];
cell.stampId.text = [[NSString alloc] initWithFormat:@"%@",card.stampNumber];
cell.createdAt.text = [[NSString alloc] initWithFormat:@"%@",card.createdAt];
cell.CardId.text = [[NSString alloc] initWithFormat:@"Carte %d",(indexPath.row+1)];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
*)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[[NSNotificationCenter defaultCenter] postNotificationName:@"cardDetail" object:nil
userInfo:nil];
}
我的问题是我应该如何根据我的图章以编程方式创建这些图片..
编辑: 我有这张图片:
UIImageView *stampIMG = [[UIImageView alloc] initWithFrame:self.view.frame];
stampIMG = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1.jpg"]];
stampIMG.frame = CGRectMake(0, 0, 122, 122);
我只想用这张图片
【问题讨论】:
-
我很困惑。这个图像应该是什么样子的?什么是“邮票”?我所看到的只是一个“stampId”,它似乎是一个数字。您打算如何从数字创建图像?
-
@maddy 我将根据该数字创建图像
-
根据号码如何?图片内容从何而来?还是您只是想要数字的图像?
-
@rmaddy 检查我的编辑
-
好的,你已经有了图片。您实际上并不想在运行时创建图像。正确的?您的问题实际上是关于如何根据邮票 id 引用现有图像?为此,您可以执行
[UIImage imageNamed:[NSString stringWithFormat:@"%@.jpg", stampId]];之类的操作。更新格式说明符以匹配stampId的类型。
标签: objective-c xcode uitableview uiimageview