首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在UITableViewCell UIPopoverController xcode5中更改静态xcode5背景色

在UITableViewCell UIPopoverController xcode5中更改静态xcode5背景色
EN

Stack Overflow用户
提问于 2014-05-26 15:38:42
回答 3查看 142关注 0票数 0

我正在为Xcode 5中的in 7.1开发一个应用程序

我想在最后一行更改tableview单元格的背景色,如下所示

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

不知怎么的,我的桌面单元失去了原来的背景色

这是我的密码:

代码语言:javascript
复制
//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:

代码语言:javascript
复制
#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

代码语言:javascript
复制
#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;

}

还有..。结果仍然一样:

EN

回答 3

Stack Overflow用户

发布于 2014-05-26 15:44:15

给我们看你的

代码语言:javascript
复制
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

您可以使用cell.backgroundColor更改单元格背景。

票数 0
EN

Stack Overflow用户

发布于 2014-05-26 16:43:32

试一试:

代码语言:javascript
复制
- (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;
}
票数 0
EN

Stack Overflow用户

发布于 2014-05-26 16:59:08

您需要在故事板中使用它来更改单元格类。

如果不创建单元格类,则应该创建扩展UITableViewCell的对象。然后您可以添加它的属性。

代码语言:javascript
复制
@interface ResultsCell : UITableViewCell
@property (nonatomic, weak) IBOutlet UILabel *lYourFirstLabel;

代码语言:javascript
复制
- (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;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23873565

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档