我有一个tableview
在控制器,显示收据及其图像,创建日期等。
我做到了这一点,当用户点击一个单元格时,它会去DetailViewController
。使用此代码:详细视图控制器从表视图控制器没有故事板?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ReceiptDetailViewController *controller = [[ReceiptDetailViewController alloc] initWithNibName:@"ReceiptDetailViewController" bundle:nil];
[self.navigationController pushViewController:controller animated:YES];
}
我想通过图像,日期,类别等,以我的新观点在UIImageView
,textView
等
这是第一个为我的表的代码控制器:
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"];
}
cell.selectionStyle = UITableViewCellSelectionStyleGray;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
Receipt *receipt = [self.receiptsArray objectAtIndex:indexPath.row];
ReceiptCategory *category = receipt.relationshipToCategory;
ReceiptImage *image = receipt.relationshipToImage;
cell.textLabel.text = category.receiptCategory;
cell.detailTextLabel.text = receipt.date.description;
if(self.imageCache.count <= indexPath.row) {
[self.imageCache addObject:[UIImage imageWithData:image.data]];
}
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
imageView.image = [self.imageCache objectAtIndex:indexPath.row];
cell.imageView.image = imageView.image;
return cell;
}
如何传递此数据?我已经搜索了两天,所有的解决方案都包含一个故事板,我不使用它。
您必须将此行添加到ReceiptDetailViewController.h @property(nonatomic,strong)Receipt * receipt;你是什么意思,你尝试添加@property,但它不起作用? – Greg
嗨格雷格,感谢您抽出时间帮助我,非常感谢。我添加了'@property(nonatomic,strong)Receipt * receipt; '添加到我的detailviewcontroller的头文件中,但它返回两个错误 - 未知类型名称'Receipt'和'带有保留或强属性的属性必须是对象类型'。我很抱歉,如果这是一个愚蠢的问题,但我将如何解决这些问题?谢谢 – user3127576
将#import“Receipt.h”添加到同一文件的顶部。它应该有所帮助。 – Greg