Iphone tableView单元格不会更改字体颜色
我已经做了很多关于从tableView单元格更改字体颜色的方法。显然这两种方法都失败了。除非我做错了,否则我需要一些帮助来纠正它。这是我在网上找到的更改字体颜色的代码Iphone tableView单元格不会更改字体颜色,iphone,uitableview,fonts,ios4,Iphone,Uitableview,Fonts,Ios4,我已经做了很多关于从tableView单元格更改字体颜色的方法。显然这两种方法都失败了。除非我做错了,否则我需要一些帮助来纠正它。这是我在网上找到的更改字体颜色的代码 [[cell textLabel] setTextColor:[UIColor colorWithRed:255.0/255.0 green:76.0/255.0 blue:76.0/255.0 alpha:1]]; 我将该行放在cellforrowatinexpath方法中,但它不起作用。接下来,我搜索了这个页面并找到了另一个
[[cell textLabel] setTextColor:[UIColor colorWithRed:255.0/255.0 green:76.0/255.0 blue:76.0/255.0 alpha:1]];
我将该行放在cellforrowatinexpath
方法中,但它不起作用。接下来,我搜索了这个页面并找到了另一个更改字体颜色的方法:tableView:willDisplayCell:forrowatinexpath:
我复制了setTextColor方法并将其粘贴到willDisplayCell
方法中,但它也不起作用。下面是我如何尝试和失败的源代码:
cellForRowAtIndexPath:
tableView:willDisplayCell:forRowAtIndexPath:
应用程序单元.h
//设置属性
@不动产布尔乌塞德背景;
@财产用途背景;
@属性(保留)NSString*strPharmacyName;
@财产(保留)UIImage*pharmacyIcon;
@属性(保留)NSString*strStoreName
ApplicationCell.m
这应该可以设置文本的颜色,我刚刚试过,效果很好。单元格应该是UITableView,但应用程序单元格是否继承UITableView单元格? 另外,如果ApplicationCell为零,我不确定tempCell发生了什么 试一试 cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle重用标识符:CellIdentifier]自动释放]
从这里开始您似乎正在使用一个自定义子类
UITableViewCell
,因为您提到了ApplicationCell
类中有很多内容。我猜您的子类没有使用textlab
字段,因为您的更改没有反映在UI上
从
ApplicationCell
接口声明和NIB
文件中检查屏幕上显示的属性插座。找到合适的属性插座后,更改其属性。在何处创建tempCell?能否发布ApplicationCell的界面?
?这是一个已创建的自定义单元格。很抱歉,这个项目是一个传下来的,所以我不是代码的合法所有者。ApplicationCell
代码非常长,要我“回答我自己的问题吗?”?或者继续编辑问题?更改单元格颜色最有趣的方法是使用UILabel
。感谢Deepak的快速回复。我稍后会试用。现在我的老板想从我这里得到一些别的东西:(好的,我已经编辑了这个问题。我有应用程序单元inserted@MelvinLai您的ApplicationCell
代码中是否提到UILabel
或textlab
?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"ApplicationCell";
ApplicationCell *cell = (ApplicationCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
[[NSBundle mainBundle] loadNibNamed:@"PharmacyCell" owner:self options:nil];
cell = tempCell;
self.tempCell = nil;
}
//cell.useDarkBackground = (indexPath.row % 2 == 0);
HealthWellness *objHealth = [self.maHealthArray objectAtIndex:indexPath.row];
cell.strPharmacyName = [objHealth.healthName stringByReplacingOccurrencesOfString:@"|" withString:@""];
[[cell textLabel] setTextColor:[UIColor colorWithRed:255.0/255.0 green:76.0/255.0 blue:76.0/255.0 alpha:1]];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
[[cell textLabel] setTextColor:[UIColor colorWithRed:255.0/255.0 green:76.0/255.0 blue:76.0/255.0 alpha:1]];
}
@interface ApplicationCell : UITableViewCell{
//variable declaration
BOOL useDarkBackground;
BOOL useMenuBackground;
NSString *strPharmacyName;
UIImage *pharmacyIcon;
NSString *strStoreName;}
- (void)setUseDarkBackground:(BOOL)flag{
if (flag != useDarkBackground || !self.backgroundView)
{
useDarkBackground = flag;
NSString *backgroundImagePath = [[NSBundle mainBundle] pathForResource:useDarkBackground ? @"BGDark" : @"BGLight" ofType:@"png"];
UIImage *backgroundImage = [[UIImage imageWithContentsOfFile:backgroundImagePath] stretchableImageWithLeftCapWidth:0.0 topCapHeight:1.0];
self.backgroundView = [[[UIImageView alloc] initWithImage:backgroundImage] autorelease];
self.backgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.backgroundView.frame = self.bounds;
}}
- (void)setUseMenuBackground:(BOOL)flag{
if (flag != useDarkBackground || !self.backgroundView)
{
useDarkBackground = flag;
NSString *backgroundImagePath = [[NSBundle mainBundle] pathForResource:useDarkBackground ? @"BGDark" : @"BGLight" ofType:@"png"];
UIImage *backgroundImage = [[UIImage imageWithContentsOfFile:backgroundImagePath] stretchableImageWithLeftCapWidth:0.0 topCapHeight:1.0];
self.backgroundView = [[[UIImageView alloc] initWithImage:backgroundImage] autorelease];
self.backgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.backgroundView.frame = self.bounds;
}}