![](/img/trans.png)
[英]UITableViewCell: how to verify the kind of accessoryType in all cells?
[英]UITableViewCell BackgroundImage for ALL Cells
我將所有UITableViewCell
的背景圖像設置為以下代碼中的相同模式:
- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.backgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"SelectAnAlbumTableViewCellBackground"]] autorelease];
}
哪個有效,除了任何空單元格。 我想知道如何設置ALL UITableViewCell
的背景,而不僅僅是那些有數據的背景?
問題是方法
`
- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
僅針對非空單元格調用。
因此,您可以增加此方法中的單元格數
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
當你在數據庫中添加數據時,你會添加標簽或你想要的東西,但當你在空單元格中時,你什么都不做。
為tableview設置該單元格圖像。
TableView.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"Cellimage.png"]];
這是我的手機圖像:
這是我的桌面視圖:
如果您需要為Cell
設置背景圖像,只需使用以下行:
UIImageView *myImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cellImage.png"]];
myImgView.frame = CGRectMake(0, 0, 300, 50);
[cell.contentView addSubview:myImgView];
通過使用此代碼,您將獲得它獲取數據原因的圖像,因為它獲取數據時只有調用。
如果要這樣做,則必須設置表格背景顏色。
希望這會有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.