Ios UIScrollView/UIView中的样式UITableViewCell 概述
我使用故事板在UIScrollView中添加了一个UITableViewIos UIScrollView/UIView中的样式UITableViewCell 概述,ios,objective-c,uitableview,uiscrollview,Ios,Objective C,Uitableview,Uiscrollview,我使用故事板在UIScrollView中添加了一个UITableView @interface NWDetailViewController : UIViewController<UITableViewDelegate, UITableViewDataSource> { IBOutlet UIScrollView *scrollView; ... IBOutlet UITableView *tableView; IBOutlet NSLayoutConstra
@interface NWDetailViewController : UIViewController<UITableViewDelegate,
UITableViewDataSource> {
IBOutlet UIScrollView *scrollView;
...
IBOutlet UITableView *tableView;
IBOutlet NSLayoutConstraint *tableViewHeightConstraint;
}
我的简单目标是在这个表视图中设置UITableViewCell的样式
代码
目前,我已将UITableView属性添加到视图控制器,并在情节提要中添加了插座
@interface NWDetailViewController : UIViewController<UITableViewDelegate,
UITableViewDataSource> {
IBOutlet UIScrollView *scrollView;
...
IBOutlet UITableView *tableView;
IBOutlet NSLayoutConstraint *tableViewHeightConstraint;
}
这就是我试图在控制器中填充单元格的方式:
-(UITableViewCell *)tableView:(UITableView *)thisTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"LocationCell";
// Same with both tableView and thisTableView
NWLocationTableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[NWLocationTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:cellIdentifier];
}
[cell.titleLabel setText:@"test"];
// or
UILabel *label = (UILabel *)[cell.contentView viewWithTag:2112];
[label setText:@"test"];
NSLog(@"%@, %@", cell.contentView.subviews, cell.class);
return cell;
}
但这两种方法都不会产生任何效果,因此我无法对其进行风格化。添加任何静态对象(例如UIButton)也不会显示
日志显示:“(),NWLocationTableViewCell”
这是一个命名问题
在方法头中,您将
thisTableView
作为要使用的tableView传递,但随后调用[tableView dequeueReusableCellWithIdentifier]代码>以获取单元格。它应该会生成一个错误,但可能还有另一个同名变量或属性?无论如何,如果这是你的逐字记录代码,那就是你的错误。你有错误吗?你怎么知道你没有手机?我不确定这是否有帮助,但试着把你的插座从支架上取下来。将它们声明为大括号下和@end
之前的属性,例如@property(强,非原子)IBUILabel*标题标签代码>@rdelmar无错误,nil表示无错误cell@gsean两种方法都试过了,但谢谢你,你的日志中没有吗?这意味着没有标题标签和标签,不一定没有细胞。你应该只记录你的手机。如果我没记错的话,如果CellFroRowatingIndexPath没有返回任何单元格,则会出现错误。是的,tableView是插座引用的属性,但使用此tableView时也会出现相同的情况also@ThomSeddon-你介意修改你的问题吗,这样其他人就不会像我一样陷入同样的陷阱?是的,我的意思是修复代码,而不是添加注释。我是为你做的。不客气。不幸的是,您的解决方案实际上并不是一个修复方案,我不确定它是否一定更正确,因此我使用了注释。这是一个修复方案,因为它确实消除了一个错误,而该错误只会被错误的命名约定所掩盖(即namg a tableViewtableView
)。另外,在委托方法中,您应该使用tableView传递给委托的tableView对象,而不是某些类变量/属性/任何东西,这一点也必然更加正确。如果你愿意,你仍然可以删除我的编辑。