2011-03-23 30 views
1

在我的第一個視圖中,我有一個UITableView 5個記錄。在UITableView單元格中擁有兩個不同的組件。一個UILabel是文本,另一個UILabel顯示該單元格的值。分層UITableview

在選擇UITableViewCell時,用戶將被導航到另一個視圖,在該視圖中,我給出了一個選擇器控制器,用於更改所選行的表視圖中第二個標籤的值。我在-viewWillAppear上重新加載了UITableView的數據,但是這多次與我訪問過的標籤重疊。

任何人都可以給我有關分層tableview的相關示例,其中UItableViewCell的右側部分依賴於從下一個視圖選擇選擇器。

+0

發佈您的代碼... – robertvojta 2011-03-23 09:47:37

+0

。我在UITableViewcell中添加這些動態標記。 \t \t CGRect lblFrame = CGRectMake(10,5,140,30); \t UILabel * lblField = [[UILabel alloc] initWithFrame:lblFrame]; \t lblField.font = [UIFont systemFontOfSize:[UIFont labelFontSize]]; \t \t CGRect firstInput_Frame = CGRectMake(300,5,200,30); \t UILabel * lblResult = [[UILabel alloc] initWithFrame:firstInput_Frame]; \t lblResult.font = [UIFont systemFontOfSize:[UIFont labelFontSize]]; \t // [txtField setBorderStyle:UITextBorderStyleNone]; \t lblField.text = @「」; \t lblResult.text = @「」 – 2011-03-23 09:59:56

回答

1

我想你每次重新載入表格時都在cell.contentView上添加標籤,但並沒有刪除以前的標籤。這就是重疊發生的原因。

嘗試刪除我的cellForRowAtIndexPath使用此標貼

- (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] autorelease]; 
    } 
    for (UIView * view in cell.contentView.subviews) { 
     [view removeFromSuperview]; 
     view = nil; 
    } 
    // add your labels 
} 
+0

謝謝。有效。我想知道是否有任何其他最佳解決方案。你想讓我更多地解釋我的問題嗎? – 2011-03-23 10:12:08

+0

可能來自這個門戶的一些大鏡頭可能會給我們一些最佳的解決方案。據我所知,我們並不是每次都創建新的單元格,而是將可重用的單元格分離出來,這些單元格已經創建並添加了一些視圖,所以在使用這種單元格之前,我更喜歡清理單元格的視圖然後對其進行自定義。當我這樣做的時候,我釋放了附加的組件..例如。 [cell.contentView addSubView:myLabel]; [myLabel發佈];這樣就沒有泄漏。 – 2011-03-23 10:17:40