0

我在 StoryBoard 应用程序中使用 UITableView。改变颜色工作,方向不起作用,分隔线仍然出现。

    - (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"row320x44.png"]];
    cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"row320x44.png"]];
    cell.textLabel.backgroundColor = [UIColor clearColor];
    cell.detailTextLabel.backgroundColor = [UIColor clearColor];
    cell.textLabel.textColor = [UIColor whiteColor];
    cell.detailTextLabel.textColor = [UIColor whiteColor];
    cell.textLabel.textAlignment = NSTextAlignmentRight;
    cell.detailTextLabel.textAlignment = NSTextAlignmentRight;

    tableView.separatorColor = [UIColor clearColor];
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

    tableView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"row320x44.png"]];
}

我在 viewDidLoad 中试过:

self.tableViewWallMessages.delegate = self;
    self.tableViewWallMessages.separatorColor = [UIColor clearColor];
    self.tableViewWallMessages.separatorStyle = UITableViewCellSeparatorStyleNone;

依然没有。有任何想法吗?

4

2 回答 2

2

试试下面的。

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    //set the separator colour in the table (menu)
    tableView.separatorColor = [UIColor clearColor];

    // Return the number of sections.
    return 1;
}

如果这不起作用,请尝试在 willDisplayCell 中添加以下内容

cell.backgroundView = [[UIView alloc] initWithFrame:CGRectZero];

或者,您可以以编程方式创建它,而不是使用情节提要

在 .h 文件中

@interface ViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
{
    UITableView *myTableView;
}
@property(nonatomic,strong)UITableView *myTableView;

在 .m 文件中

- (void)viewDidLoad
{
    myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
    myTableView.dataSource = self;
    myTableView.delegate = self;
    [myTableView reloadData];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    //set the separator colour in the table (menu)
tableView.separatorColor = [UIColor clearColor];

    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    //set the number of rows in the table (menu) as 6
    int noRows = 6;
    return noRows;

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
//set the row height for the table (menu)
    return 100;
}

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

    static NSString *CellIdentifier = @"Cell";

    //Create a title label in the table (menu)
    UILabel *titleLabel;


    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

        /**TITLE LABEL SETUP**/
        //setup the title label
        titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 54.0, 77, 33)];
        titleLabel.tag = TITLE_TAG;


        //add the title label to the cell
    [cell.contentView addSubview:titleLabel];



}
else
{
    //recall the existing cell content if it has already been created
    titleLabel = (UILabel*)[cell.contentView viewWithTag:TITLE_TAG];

}

//set the icon image as the image from the array


//set the menu item title from the array
titleLabel.text = @"some text";

//dont show the clicked cell as highlighted
cell.selectionStyle = UITableViewCellSelectionStyleNone;




    return cell;

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //Code to execute when a cell is clicked on
}
于 2013-05-29T10:09:28.430 回答
2

尝试在 Storyboard 文件中设置分隔符值“无”。

在此处输入图像描述

您的代码是正确的,只需确保您已将 UITableView 插座与故事板连接。

于 2013-05-29T10:31:40.043 回答