2016-10-14 55 views
0

如何保持UITableViewCell textLabel位置固定在滑動狀態,同時使用默認UITableViewCell如何保持UITableViewCell textLabel位置固定在滑動狀態?

在滑動textLabel文本向左和向外移動屏幕。

相關代碼:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 
    // Return YES if you want the specified item to be editable. 

     return YES; 
} 

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 

     if (editingStyle == UITableViewCellEditingStyleDelete) { 

      //code related to delete row 

     } 

} 

支票影像低於清醒的認識:

刷卡前:

enter image description here

刷卡後:

enter image description here

+0

@Ronak這是默認設置。如果你想在滑動後想看到可見的標籤值,那麼在滑動後改變UILabel Position意味着像這樣設置frame'self.lbl.frame = CGRectMake(100,5,50,10)'。 –

+0

在setEditing方法中,您可以調整文本標籤的約束和框架 – Flipper

+0

'問題可以被標記爲無效'您能解釋爲什麼嗎?@Sharpkits –

回答

0

請試試這個:

#pragma mark- swipeable cell 

    -(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
      UITableViewCell *cell = (UITableViewCell *)[tableView cellForRowAtIndexPath:indexPath]; 

      cell.textLabel.frame=CGRectMake(30, 2, 50, 10); 

      UITableViewRowAction *unlink_button = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) 
       { 

        [self.accountsTable reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone]; 
        cell.textLabel.frame=CGRectMake(0, 2, 50, 10); 
        [self deleteFunction]; 
       }]; 
      unlink_button.backgroundColor = [UIColor redColor]; //arbitrary color 

      return @[unlink_button]; 
    } 

    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 
     // you need to implement this method too or nothing will work: 

    } 

    - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
    return YES; 
    } 
0
- (void)layoutSubviews 
{ 
    [super layoutSubviews]; 
    CGSize size = self.bounds.size; 
    CGRect frame = CGRectMake(4.0f, 4.0f, size.width, size.height); 
    self.textLabel.frame = frame; 
    self.textLabel.contentMode = UIViewContentModeScaleAspectFit; 
} 

覆蓋此方法...

0

我覺得內容查看當你刷卡動作,所以試試這個:

- (void)layoutSubviews 
{ 
    [super layoutSubviews]; 
    CGRect frame = CGRectOffset(self.textLabel.frame,0-self.contentView.frame.x,0); 
    self.textLabel.frame = frame; 
} 
+0

如何使用'layoutSubviews'作爲默認單元格? –

+0

你將不得不細分細胞以改變它的行爲 –

相關問題