2012-11-28 40 views
0

我正在製作iPhone應用程序。在這個應用程序中,我有一個UITableView它有一個UITableView頭。這是我的代碼的樣子。UITableView headerview不斷重複

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(30, 0, 308, 50)]; 
    view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"sx_home_tablehead.png"]]; 
    self.tableViewAppointments.tableHeaderView = view; 

,這是它的樣子在我的iPhone

enter image description here 這是我想達到

enter image description here

。希望有人能幫助我的!

親切的問候!

+0

通過實現委託方法添加它作爲表視圖節頭 – iDev

回答

0

定義頁眉的高度,因爲你」重新明確指定視圖的框架。你不應該這樣做一個可怕的黑客。使用此片的代碼,而不是:

UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"header.png"]]; 
self.tableView.tableHeaderView = imgView; 
+0

這對我有效!但是我必須做些什麼來使它像上面的截圖一樣? – Steaphann

+0

@StefGeelen我懷疑如果你這樣做,你會得到預期的結果(提供的圖像是適當的大小)。 – 2012-11-28 19:12:52

+0

你需要什麼? – Steaphann

0

如果你想將其添加爲一個表格視圖節頭,你需要添加如下它,

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{ 

    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(30, 0, 308, 50)]; 
    view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"sx_home_tablehead.png"]]; 
//or, 
    UIImageView *view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sx_home_tablehead.png"]]; 
    return view; 
} 

可以在

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section 
{ 
    return height; 
} 
+0

這不設置表頭的視圖,但節頭。 – 2012-11-28 18:49:37

+0

是的,的確如此。如果他想要附加表格視圖部分,這是他正在尋找的人。否則你的是正確的。 – iDev