我正在为Xcode 5中的in 7.1开发一个应用程序
我想在最后一行更改tableview单元格的背景色,如下所示

但是,当我在一个UITableViewController中调用这个UIPopoverController时,我得到了这样的信息:

不知怎么的,我的桌面单元失去了原来的背景色
这是我的密码:
//iPad Popover Section
if (!resultBTPopover || !resultBTPopover.popoverVisible)
{
ResultadosBalanceTransferVC *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"ResultadosBalanceTransferVC"];
//controller.delegate = self;
controller.title = @"Resultados";
controller.amountValue = self.amountTextfield.text;
controller.promoRateValue = self.promoRateTextfield.text;
controller.normalRateValue = self.normalRateTextfield.text;
controller.otherBankRateValue = self.otherBankRateTextfield.text;
controller.termValue = self.termTextfield.text;
navController = [[UINavigationController alloc]initWithRootViewController:controller];
navController.toolbarHidden = FALSE;
NSDictionary *textAtributesDictionaryTitle = [NSDictionary dictionaryWithObjectsAndKeys:
UIColorFromRGB(toolbarTintColor), NSForegroundColorAttributeName,
[UIFont fontWithName:@"HelveticaNeue-BoldCond" size:19.0f], NSFontAttributeName,
nil];
[navController.navigationBar setTitleTextAttributes:textAtributesDictionaryTitle];
resultBTPopover = [[UIPopoverController alloc] initWithContentViewController:navController];
[resultBTPopover presentPopoverFromRect:CGRectMake(self.view.center.x - (self.view.center.x * .2734), self.view.center.y - (self.view.center.y * .6510), 300, 400)
inView:self.view permittedArrowDirections:0
animated:YES];
}
else{
[resultBTPopover dismissPopoverAnimated:YES];
resultBTPopover = nil;
}
}如何获得我原来的表视图单元格颜色??
谢谢你的支持
编辑:I将使用Plokstorm提出的方法
结果.h:
#import <UIKit/UIKit.h>
@interface ResultsCell : UITableViewCell
@property (nonatomic, weak) IBOutlet UILabel *label1;
@property (nonatomic, weak) IBOutlet UILabel *label2;
@property (nonatomic, weak) IBOutlet UILabel *label3;
@property (nonatomic, weak) IBOutlet UILabel *label4;
@property (nonatomic, weak) IBOutlet UILabel *label5;
@end在故事板上,我这样做了:

它们都更改为ResultsCell自定义类。

将所有属性与UITableViewCell的可视标签链接
在代码中,我这样做是为了测试:
ResultadosBalanceTransferVC.m
#import "ResultsCell.h"
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
ResultsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (cell == nil) {
cell = [[ResultsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
}
if (indexPath.row == 2){
cell.backgroundColor = [UIColor redColor];
cell.label1.text = @"Pago Total";
}
return cell;
}还有..。结果仍然一样:

发布于 2014-05-26 15:44:15
给我们看你的
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath您可以使用cell.backgroundColor更改单元格背景。
发布于 2014-05-26 16:43:32
试一试:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
}
if (indexPath.row == 2)
cell.backgroundColor = [UIColor redColor];
return cell;
}发布于 2014-05-26 16:59:08
您需要在故事板中使用它来更改单元格类。
如果不创建单元格类,则应该创建扩展UITableViewCell的对象。然后您可以添加它的属性。
@interface ResultsCell : UITableViewCell
@property (nonatomic, weak) IBOutlet UILabel *lYourFirstLabel;- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
ResultsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (cell == nil) {
cell = [[ResultsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
}
if (indexPath.row == 2)
cell.backgroundColor = [UIColor redColor];
[cell.lYourFirstLabel setText:@"hello"];
return cell;
}https://stackoverflow.com/questions/23873565
复制相似问题