IOS 6: Editing and Autoresizing a UITableView

Hey. Can someone help me understand how to automatically compose table cell elements when editing in iOS 6.0? I set AutoLayout FALSE for the UITableViewCell Autosizing parameter set in the upper right corner of the Attributes Inspector! Images on the right side of the image are overlapped by delete buttons. Please refer to the attached image. Below is the code for this. Anyway, can I fix this problem?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { PlayerCell *cell = (PlayerCell *)[tableView dequeueReusableCellWithIdentifier:@"PlayerCell"]; Player *player = [self.players objectAtIndex:indexPath.row]; cell.nameLabel.text = player.name; cell.gameLabel.text = player.game; cell.ratingImageView.image = [self imageForRating:player.rating]; return cell; } - (UIImage *)imageForRating:(int)rating { switch (rating) { case 1: return [UIImage imageNamed:@"1StarSmall.png"]; case 2: return [UIImage imageNamed:@"2StarsSmall.png"]; case 3: return [UIImage imageNamed:@"3StarsSmall.png"]; case 4: return [UIImage imageNamed:@"4StarsSmall.png"]; case 5: return [UIImage imageNamed:@"5StarsSmall.png"]; } return nil; } - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { [self.players removeObjectAtIndex:indexPath.row]; [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; } } 

I have added the following delegate methods and it works great when I scroll the cell.

 -(void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath { PlayerCell *cell = (PlayerCell *)[tableView cellForRowAtIndexPath:indexPath]; cell.ratingImageView.hidden = YES; } - (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath { PlayerCell *cell = (PlayerCell *)[tableView cellForRowAtIndexPath:indexPath]; cell.ratingImageView.hidden = NO; } 

... but these methods are not called when the editButtonItem button is clicked! This is strange! I'm missing something. I added the following method, which is called when the "Edit / Finish" button is clicked, but there is no way to detect the cell that will be selected for editing!

 - (void)setEditing:(BOOL)editing animated:(BOOL)animate { [super setEditing:editing animated:animate]; if(editing) { NSLog(@"editMode on"); } else { NSLog(@"Done leave editmode"); } } 

When the user clicks the round button on the left, is there a way to add a selector to this button and get the cell index?

Image

+4
source share
1 answer

Your Rating ImageView uses automatic masks to resize and position when you are not using AutoLayout. By default, this means that the distance to the left and top is fixed and the size will not change.

When you switch a cell to edit content that moves and changes, but your ImageView rating remains fixed in the top and left. You can visualize this temporarily (for training), set the background color for the contentView content and see how it changes when you edit and delete a cell.

What you want is your rating to stay at a fixed distance from the right edge, not the left. You can either change this in InterfaceBuilder (where you make your XIB or Storyboard), or in code by setting the autoresizingMask property in ratingImageView.


Go to this tab

Go to this tab

Change auto isolation as follows

enter image description here

Or do it in code

 // in code you specify what should be flexible instead of what should be fixed... [ratingImageView setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin]; 
+6
source

Source: https://habr.com/ru/post/1436557/


All Articles