Objective c 静态表视图的自定义单元格未更新
我有一个静态的表视图,有两组两个单元格。 我有一个自定义单元格xib,里面有图片和一些数据。 我已经通过故事板声明该单元是我的自定义单元的一种类型,并且我在视图中有一个函数,用于设置该单元的照片及其数据。问题是单元格一直是空的。我甚至尝试将数据重新加载到表中。我错过了什么?我对故事公猪和观景片不熟悉 我正在使用的代码:Objective c 静态表视图的自定义单元格未更新,objective-c,xcode,storyboard,tableview,Objective C,Xcode,Storyboard,Tableview,我有一个静态的表视图,有两组两个单元格。 我有一个自定义单元格xib,里面有图片和一些数据。 我已经通过故事板声明该单元是我的自定义单元的一种类型,并且我在视图中有一个函数,用于设置该单元的照片及其数据。问题是单元格一直是空的。我甚至尝试将数据重新加载到表中。我错过了什么?我对故事公猪和观景片不熟悉 我正在使用的代码: @interface CAUploadDetailsViewController () @property (weak, nonatomic) IBOutlet CAConten
@interface CAUploadDetailsViewController ()
@property (weak, nonatomic) IBOutlet CAContentCell *currentUploadedFile;
@property (strong, nonatomic) IBOutlet UITableView *table;
@end
@implementation CAUploadDetailsViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// self.tableView.delegate = self;
CAContent* content = [[CAContent new] init];
content.name = @"file.txt";
content.sizeInBytes = 4444;
self.currentUploadedFile.item = content;
// Do any additional setup after loading the view.
// self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"ExplorerBackground3"]];
[self.tableView reloadData];
}
- (void)viewWillAppear:(BOOL)animated
{
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
当我设置该项时,它具有以下代码:
- (void)setItem:(id)item
{
_item = item;
// Cast content
CAContent* content = (CAContent *)item;
self.labelTitle.text = content.name;
NSString* icon = @"MyIcon";
// Set icon image
self.imageIcon.image = [UIImage imageNamed:icon];
}
==2015年1月25日更新===
我已经设法用CellForRowatineXpath解决了这个问题,但是我觉得这个解决方案有点奇怪,我不喜欢这个代码——这就是自定义单元格应该如何处理的吗?因为我只需要1个单元格就可以自定义,所以我的表中有2个单元格
- (void)viewDidLoad
{
[super viewDidLoad];
// self.tableView.delegate = self;
// Customize background
self.view.layer.contents = (id)[UIImage imageNamed:@"ExplorerBackground3"].CGImage;
// Register cell nib
[self.table registerNib:[UINib nibWithNibName:@"CAContentCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"CAContentCell"];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// we should configure only the first cell.
if (indexPath.section == 0 && indexPath.row == 0)
{
CAContentCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CAContentCell"];
if (cell == nil) {
cell = [[NSBundle mainBundle] loadNibNamed:@"CAContentCell"
owner:self
options:nil][0];
}
CAContent* content = [[CAContent new] init];
content.name = @"file.txt";
content.sizeInBytes = 4444;
cell.item = content;
return cell;
}
return [super tableView:tableView cellForRowAtIndexPath:indexPath];
}
可能您在设置照片后忘记调用[tableView reloadData]?显示您的代码。我尝试在viewdidload调用它,但仍然。空牢房。我明天会在办公室发布整个代码嗨,添加了代码示例。