2013-06-25 48 views
0

我已將3個uilabels添加到uitableview單元格中。我遇到的問題是當我滑動刪除時,單元格右側的UILabel不會移動,因此刪除按鈕和UILabel相互重疊。我已經發布了一些我的代碼如下。輸入編輯時在定製單元格上移動UILabel

我使用故事板開發了我的佈局,所以從我讀的內容來看,框架不會有幫助。

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

    NSString *baseTableCellIdentifier = @"baseCell"; 


    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:baseTableCellIdentifier]; 

    BaseInfo *infoAtIndex = [[[DataClass getInstance] allItems] objectAtIndex:[indexPath row]]; 


    baseName = (UILabel *)[cell viewWithTag:1]; 

    baseICAO = (UILabel *)[cell viewWithTag:2]; 

    baseTime = (UILabel *)[cell viewWithTag:3]; 

    [cell.contentView addSubview:baseName]; 
    [cell.contentView addSubview:baseICAO]; 
    [cell.contentView addSubview:baseTime]; 

    [baseName setText:[infoAtIndex name]]; 
    [baseICAO setText:[infoAtIndex icao]]; 



    baseTimeZome = [NSTimeZone timeZoneWithName:[infoAtIndex timeZone]]; 
    [baseDate setDateFormat:@"HH:mm"]; 
    [baseDate setTimeZone:baseTimeZome]; 

    NSString *baseTimeString = [baseDate stringFromDate:[NSDate date]]; 
    [baseTime setFont:[UIFont boldSystemFontOfSize:20]]; 
    [baseTime setText:baseTimeString] ; 


    return cell; 
} 


-(void)setEditing:(BOOL)editing animated:(BOOL)animated{ 

    if (editing) { 

     //no idea what to put here 

    }else{ 

    } 



} 
+0

你有沒有試過設置你的'UILabel autoresizemask'?如果你沒有使用AutoLayout。 –

回答

1

在你UITableViewCell子類中重寫setEditing:animated:和執行有任何佈局的變化。正如評論者所說,您可能無需爲標籤的autoresizingMask設置適當的值。

+0

我用它來修復它。 (BOOL)編輯動畫:(布爾)動畫{ [super setEditing:editing animated:animated]; CGPoint frame = baseTime.center; if(editing &&!self.showingDeleteConfirmation){ frame.x = 200; self.baseTime.center = frame; }否則如果(!編輯){frame = 246; self.baseTime.center = frame; } } – acithium

0

您應該創建一個單元格子類。然後你可以實現setEditing:animated:來修改子視圖框架。

相關問題