我正在尝试更改UITableViewHeaderFooterView的背景颜色.虽然视图正在显示,但背景颜色仍然是默认颜色.我从xcode获取日志说:
不推荐在UITableViewHeaderFooterView上设置背景颜色.请改用contentView.backgroundColor.
但是,以下选项均不起作用:
myTableViewHeaderFooterView.contentView.backgroundColor = [UIColor blackColor];
myTableViewHeaderFooterView.backgroundView.backgroundColor = [UIColor blackColor];
myTableViewHeaderFooterView.backgroundColor = [UIColor blackColor];
Run Code Online (Sandbox Code Playgroud)
我也尝试在xib文件中更改视图的背景颜色.
有什么建议?谢谢.
我有一个UITableView,在某些情况下,空是合法的.因此,我宁愿在屏幕上打印友好的消息,而不是显示应用程序的背景图像,例如:
此列表现在为空
最简单的方法是什么?
在我运行包含tableview单元格的应用程序后更新到Xcode 6.1 beta 2后,调试助手说:
Warning once only: Detected a case where constraints ambiguously suggest a height of zero for a tableview cell's content view. We're considering the collapse unintentional and using standard height instead.
Run Code Online (Sandbox Code Playgroud)
之前,当我在这个项目上使用Xcode 5时,我会遇到一些错误,但是自从我升级后它们已经消失了.我现在没有其他错误或警告.我已经尝试调整所有tableview单元格的大小,并尝试使用标准高度,但我仍然得到相同的警告:
Warning once only: Detected a case where constraints ambiguously suggest a height of zero for a tableview cell's content view. We're considering the collapse unintentional and using standard height instead.
Run Code Online (Sandbox Code Playgroud)
我也阅读了所有类似的主题,但他们的解决方案都没有帮助.当我使用模拟器测试应用程序时,应用程序运行正常,除了应该在tableView单元格中的图片不存在.
有没有办法找出什么时候UITableView从数据源请求数据?
相关视图控制器()的viewDidLoad/ viewWillAppear/ viewDidAppear方法UITableViewController都没有在这里使用,因为它们都过早发生.它们(完全可以理解)都不保证对数据源的查询暂时完成(例如,直到滚动视图).
一个解决办法,我发现是调用reloadData的viewDidAppear,因为当reloadData返回时,表视图是保证完成尽可能多的,因为它需要暂时查询的数据源.
但是,这看起来相当令人讨厌,因为我认为这是因为reloadData它首次加载时会导致数据源被要求提供相同的信息两次(一次是自动的,一次是因为调用).
我想要这样做的原因是我想要保留 - 的滚动位置UITableView- 但是直到像素级别,而不仅仅是最近的行.
当恢复滚动位置(使用scrollRectToVisible:animated:)时,我需要表视图中已经有足够的数据,否则scrollRectToVisible:animated:方法调用什么都不做(如果您将调用单独放在任何一个中viewDidLoad,则会发生这种情况,viewWillAppear或者viewDidAppear).
我已经为此工作了大约2天,所以我想我和你分享我的经验.
问题是:是否可以使分组的UITableView中的单元格宽度更小?
答案是不.
但是有两种方法可以解决这个问题.
解决方案#1:更薄的表 可以更改tableView的框架,以便表格更小.这将导致UITableView以减小的宽度渲染内部单元格.
对此的解决方案可能如下所示:
-(void)viewWillAppear:(BOOL)animated
{
CGFloat tableBorderLeft = 20;
CGFloat tableBorderRight = 20;
CGRect tableRect = self.view.frame;
tableRect.origin.x += tableBorderLeft; // make the table begin a few pixels right from its origin
tableRect.size.width -= tableBorderLeft + tableBorderRight; // reduce the width of the table
tableView.frame = tableRect;
}
Run Code Online (Sandbox Code Playgroud)
解决方案#2:让图像呈现细胞
此解决方案在此处描述:http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html
我希望这些信息对您有所帮助.我花了大约2天时间尝试了很多可能性.这就是剩下的.
我有一个使用自动布局在故事板中定义UITableView的自UITableViewCell定义.细胞有几条多线UILabels.
在UITableView出现要正确计算单元格高度,但在最初的几个细胞高度不正确的标签之间的分歧.滚动一下后,一切都按预期工作(即使是最初不正确的单元格).
- (void)viewDidLoad {
[super viewDidLoad]
// ...
self.tableView.rowHeight = UITableViewAutomaticDimension;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
TableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"TestCell"];
// ...
// Set label.text for variable length string.
return cell;
}
Run Code Online (Sandbox Code Playgroud)
有什么我可能会遗漏,导致自动布局在前几次无法完成其工作吗?
我已经创建了一个演示此行为的示例项目.

我有一个tableview,有时可能没有任何结果列出,所以如果没有结果(标签或一个表视图单元?),我想提出一些说"没有结果"的东西.
有最简单的方法吗?
我会尝试在label后面tableview根据结果隐藏其中一个,但是因为我正在使用a TableViewController而不是正常ViewController我不确定那是多么聪明或可行.
我也使用Parse和子类化为PFQueryTableViewController:
@interface TableViewController : PFQueryTableViewController
Run Code Online (Sandbox Code Playgroud)
我可以提供所需的任何其他详细信息,请告诉我!
TableViewController 故事板中的场景:

编辑: Per Midhun MP,这是我正在使用的代码
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
NSInteger numOfSections = 0;
if ([self.stringArray count] > 0)
{
self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
numOfSections = 1;
//yourTableView.backgroundView = nil;
self.tableView.backgroundView = nil;
}
else
{
UILabel *noDataLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.tableView.bounds.size.width, self.tableView.bounds.size.height)];
noDataLabel.text = @"No data available";
noDataLabel.textColor = [UIColor blackColor];
noDataLabel.textAlignment = …Run Code Online (Sandbox Code Playgroud) 我UITableView在Interface Builder中创建了一个storyboards.的UITableView是设置有static cells与多个不同的部分.
我遇到的问题是我正在尝试用几种不同的语言设置我的应用程序.要做到这一点,我需要能够以UITableView某种方式更改部分标题.
请有人帮帮我吗?理想情况下,我想用这个问题来解决这个问题,IBOutlets但我怀疑在这种情况下甚至不可能.任何建议和意见将非常感谢.
提前致谢.
我正在以编程方式使用自动布局约束来布局我的自定义UITableView单元格,并且我正确地定义了单元格大小 tableView:heightForRowAtIndexPath:
它在iOS6上运行得很好,在iOS7中看起来也很好
但是当我在iOS7上运行应用程序时,这是我在控制台中看到的那种消息:
Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2013-10-02 09:56:44.847 Vente-Exclusive[76306:a0b] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or …Run Code Online (Sandbox Code Playgroud) 我们的一个应用程序屏幕要求我们放置UICollectionView一个UITableViewCell.这UICollectionView将具有动态数量的项目,从而产生必须动态计算的高度.但是,我在尝试计算嵌入式高度时遇到了问题UICollectionView.
我们的总体设计UIViewController是在故事板中创建的,并且确实利用了自动布局.但是,我不知道如何动态增加UITableViewCell基于高度的高度UICollectionView.
任何人都可以提供一些如何实现这一目标的建议或建议吗?
uitableview ×10
ios ×9
iphone ×5
autolayout ×2
objective-c ×2
xcode ×2
iboutlet ×1
ios7 ×1
ios8 ×1
ipad ×1
swift ×1
uistoryboard ×1
uiview ×1
width ×1