簡體   English   中英

iOS Storyboard-創建自定義的UITableViewCell

[英]iOS Storyboard - creating customized UITableViewCell

我正在嘗試通過Storyboard為我的iPhone App創建一個自定義UITableViewCell(注意:這是iOS 7)。

每個單元都有點復雜,由帶有幾個標簽的UIView組成。 換句話說,我想通過自定義單元格本身的內容視圖來設置原型單元格。

這是我嘗試的步驟:

  1. 將UIView拖到Storyboard中的Table View中,並將其標記設置為1。
  2. 為該UIView添加了一個標簽(最終,我將需要多個標簽)。
  3. 實現了一些基本的表視圖方法:

如下:

-(int)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10;
}

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

    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

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

    UIView *view = (UIView *)[cell viewWithTag:1];
    NSLog(@"%@",view); //this just prints "(null)" a bunch of times

    return cell;
}

這是我的GUI元素的層次結構。

在此處輸入圖片說明

這是我已將UIView的標簽設置為1的演示。

在此處輸入圖片說明

這是UITableView:

在此處輸入圖片說明

它多次打印(null) 正確的方法是什么? 我沒有成功找到通過情節UITableViewCells構建的復雜自定義UITableViewCells任何教程。

我認為您需要將UITableViewCell拖放到UITableView而不是UIView

這是屏幕截圖:

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM