2012-02-08 69 views
1

我有一個應用程序,裏面有幾個UITableViews,如果其中一個是空的,我想顯示一些幫助文本,浮動在UITableView之前:如果UITableView發生空白,請在UITableView上顯示一些幫助文本

「看起來你還沒有爲這個列表創建任何東西,通過點擊上面的按鈕來創建你的第一個條目。」

我該如何展示這個視圖,在UITableView之前浮動?

  1. 將使用什麼方法的UITableViewDelegate來呈現此視圖?
  2. 代碼是什麼樣子來呈現視圖?
  3. 一旦用戶添加內容,UITableViewDelegate的哪個方法將用於隱藏此視圖?

這裏有一個快速樣機:

Mockup

+0

你可以使用['MBProgressHUD'](https://github.com/jdg/MBProgressHUD) – Ilanchezhian 2012-02-08 06:34:19

回答

2

申報.h文件中

的UIView *根;

在.m文件

進口QuartzCore/QuartzCore.h

- (void)viewDidLoad 
{ 

[super viewDidLoad]; 

    root = [[UIView alloc] initWithFrame:CGRectMake(60, 50, 220, 250)]; 
    root.backgroundColor=[UIColor grayColor]; 
    root.layer.cornerRadius=10; 
    UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(10, 100, 200, 50)]; 
    label.backgroundColor=[UIColor clearColor]; 
    label.numberOfLines=3; 
    label.font=[UIFont fontWithName:@"Arial" size:14]; 
    label.lineBreakMode=UILineBreakModeTailTruncation; 
    label.textColor=[UIColor whiteColor]; 
    [email protected]"Make your first entry by tapping the button at the top of the screen"; 
    [root addSubview:label]; 
    [self.view addSubview:root]; 
} 

您的按鈕事件方法內

[根removeFromSuperview];

1

在viewDidLoad中/出現, 創建一個視圖,並將其添加爲子視圖[self.view addSubview:infoView]。在+按鈕的單擊事件從上海華盈刪除[infoView removeFromSuperView]

0

我會創建/刪除numberOfRowsInSection中的視圖(如果它是0,然後顯示視圖)或任何它被稱爲。至於視圖本身,在自定義視圖中有一個UILabel。要添加圓角等,您可以訪問視圖的圖層,該圖層是CALayer。哦,並確保你有一個ivar的視圖,所以你可以很容易地刪除它,並檢查它是否可見。並且確保在顯示視圖時始終重新載入表視圖,否則將不會調用numberOfRowsInSection。