Fry*_*Fry 1 objective-c uitableview ios
我有UITableViewCell一个.xib关联的子类.我不知道为什么但是在init之后,表视图仍然是空的,没有单元格.如果我旋转iPad,神奇地出现了单元格.
在viewDidLoad我已经注册表视图.xib
- (void)viewDidLoad
{
self.tableView.allowsMultipleSelectionDuringEditing = YES;
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.alpha = 0.0f;
[self.tableView registerNib:[UINib nibWithNibName:@"VirtualFileTableViewCell" bundle:[NSBundle mainBundle]]
forCellReuseIdentifier:VirtualFileTableViewCellReuseID];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
self.tableView.contentInset = UIEdgeInsetsMake([self.topLayoutGuide length], 0.0f, [self.bottomLaoyout guide length], 0.0f);
self.tableView.scrollIndicatorInsets = UIEdgeInsetsMake([self.topLayoutGuide length], 0.0f, [self.bottomLaoyout guide length], 0.0f);
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:NO];
[UIView animateWithDuration:0.5f animations:^{
self.tableView.alpha = ( self.viewType == ViewTypeList ? 1.0f : 0.0f );
} completion:^(BOOL finished) {}];
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * CellIdentifier = VirtualFileTableViewCellReuseID;
VirtualFileTableViewCell * cell = (VirtualFileTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.sizeLabel.text = @"5 KB";
return cell;
}
Run Code Online (Sandbox Code Playgroud)
在具有完全相同的过程的同一项目中的其他表视图中,一切正常.想法?
我注意到另一个重要的细节.问题是由这两行产生的
self.tableView.contentInset = UIEdgeInsetsMake([self.topLayoutGuide length], 0.0f, [self.bottomLaoyout guide length], 0.0f);
self.tableView.scrollIndicatorInsets = UIEdgeInsetsMake([self.topLayoutGuide length], 0.0f, [self.bottomLaoyout guide length], 0.0f);
Run Code Online (Sandbox Code Playgroud)
在viewDidAppear.我试图插入viewDidLoad和所有的工作,但问题是,我不能使用topLayoutGuide,bottomLayoutGuide因为viewDidLoad他们没有正确的价值.
相反,如果我使用默认单元格没有xib这两行不会产生问题,所有工作正常.
尝试VirtualFileTableViewCell * virtualFileTableViewCellObj在TableView".h"文件中创建自定义单元格的对象,并在以下代码中编写以下代码cellForRowAtIndexPath: -
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * CellIdentifier = VirtualFileTableViewCellReuseID;
if(virtualFileTableViewCellObj == nil)
{
virtualFileTableViewCellObj= (VirtualFileTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
}
virtualFileTableViewCellObj.sizeLabel.text = @"5 KB";
return virtualFileTableViewCellObj;
}
Run Code Online (Sandbox Code Playgroud)
更新:
写下面提到的行 ViewDidAppear
self.tableView.delegate = self;
self.tableView.dataSource = self;
Run Code Online (Sandbox Code Playgroud)
希望能帮助到你.
| 归档时间: |
|
| 查看次数: |
166 次 |
| 最近记录: |