gpt4 book ai didi

iOS 7 : Custom UITableViewCell content doesn't move expected on editing?

转载 作者:可可西里 更新时间:2023-11-01 03:07:08 26 4
gpt4 key购买 nike

我正在编辑自定义 UITableViewCell。当我进入编辑模式时,标签和图像没有正确移动。

enter image description here

- (IBAction) EditTable:(id)sender{
UIButton *btn = (UIButton *)sender;
if(self.editing) {
[super setEditing:NO animated:NO];
[btn setTitle:@"edit" forState:UIControlStateNormal];
[tblView setEditing:NO animated:NO];
} else {
[super setEditing:YES animated:YES];
[btn setTitle:@"done" forState:UIControlStateNormal];
[tblView setEditing:YES animated:YES];
}
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
int count = [arrData count];
if(self.editing) [arrData count];
return count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
DeleteUserCell *cell = (DeleteUserCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"DeleteUserCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.imgCell.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d", indexPath.row+1]];
cell.lblCell.text = [arrData objectAtIndex:indexPath.row];
return cell;
}

// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[arrData removeObjectAtIndex:indexPath.row];
[tblView reloadData];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}

最佳答案

您应该将所有自定义单元格的 subview 添加到单元格的 contentView 而不是单元格的 View 。

如果您通过Interface Builder 制作自定义单元格,您可以很容易地在Interface Builder 中找到自定义单元格的contentView。否则,如果没有 Interface Builder,请检查具有 contentView 属性的 UITableViewCell。

编辑:仅供引用,检查 UITableViewCell 中的以下注释。

// If you want to customize cells by simply adding additional views, you should add them to the content view so they will be positioned appropriately as the cell transitions into and out of editing mode.
@property (nonatomic, readonly, retain) UIView *contentView;

关于iOS 7 : Custom UITableViewCell content doesn't move expected on editing?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21283381/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com