简体   繁体   English

更改UIPopoverController xcode5中的静态UITableViewCell背景色

[英]change static UITableViewCell background color inside a UIPopoverController xcode5

I'm developing an app for iOS7.1 in Xcode 5 我正在Xcode 5中为iOS7.1开发应用程序

And I want to change tableview cell's background color at the final row to look like this 我想在最后一行更改tableview单元格的背景颜色,使其看起来像这样

在此处输入图片说明

but when I call this UITableViewController inside a UIPopoverController I get this: 但是当我在UIPopoverController内部调用此UITableViewController时,会得到以下信息:

在此处输入图片说明

Somehow my tableview cell lost it's original background color 不知何故,我的tableview单元格丢失了它的原始背景色

this is my code: 这是我的代码:

//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;
        }
    }

how to get my original tableview cell colors??? 如何获得我原来的tableview单元格颜色???

thanks in advance for the support 预先感谢您的支持


EDIT: I'll put method proposed by Plokstorm 编辑:我将把由Plokstorm提出的方法

ResultsCell.h: ResultsCell.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

on STORYBOARD I did this: 在STORYBOARD上,我这样做:

在此处输入图片说明

all of them changed to ResultsCell custom class 所有这些都更改为ResultsCell自定义类

在此处输入图片说明

linked all the properties with visual labels of the UITableViewCell 用UITableViewCell的可视标签链接所有属性

on CODE I did this for testing: 在CODE上,我这样做是为了进行测试:

ResultadosBalanceTransferVC.m 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;

}

and... still getting same result: 并且...仍然得到相同的结果:

在此处输入图片说明

Show us your 告诉我们你的

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

You can change a cell background with cell.backgroundColor . 您可以使用cell.backgroundColor更改单元格背景。

Try that: 试试看:

- (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;
}

You need to change cell class with it in storyboard. 您需要在情节提要中更改单元格类。

If you don't create a cell class, you should create an object which extends UITableViewCell. 如果不创建单元格类,则应创建一个扩展UITableViewCell的对象。 Then you can add its property. 然后,您可以添加其属性。

@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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM