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 ファイルで Separator の値を "None" に設定してみてください。

ここに画像の説明を入力

コードは正しいです。 UITableView アウトレットをストーリーボードに接続していることを確認してください。

于 2013-05-29T10:31:40.043 に答える