【发布时间】:2014-02-12 12:54:11
【问题描述】:
我正在使用自定义 UITableViewCell 进行编辑。当我进入编辑模式时,标签和图像没有正确移动。
- (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
}
}
【问题讨论】:
-
您好,您在为这个项目使用 Autolayout 吗?
-
分享您的单元格故事板布局视图将帮助我们找出问题所在。
-
@bhavyakothari 不,我没有在这个项目中使用自动布局... :(
标签: ios iphone objective-c ios7 xcode5