单元格的UITableView内容在编辑时不会移动 [英] UITableView content of cell dont move on editing
问题描述
我有一个带有某些自定义单元格的UITableView
.在每个单元格中,都有一个ImageView
和三个标签,并从字符串数组获取数据.我已经在情节提要中完成了布局.数据源是一个字符串数组.这行得通.
I have a UITableView
with some custom cells. In each cell, there is a ImageView
and three labels and get the data from a string array. I have done the layout in my storyboard. The data source is a string array. This works.
现在,我在代码中插入了EditButton
.现在我可以看到EditButton
了,但是当我激活编辑模式时,表格单元格将被调整大小,但是图像和标签不会移动.
Now I have insert a EditButton
in the code. Now i can see the EditButton
, but when I activate the edit mode the table cell will be resized, but the images and labels dont move.
您能告诉我如何移动单元格的内容吗?谁知道UITableView
的教程使用EditMode和情节提要.我发现的所有教程都基于旧的" Xcode.
Can you show me how to move the content of the cell? Who knows a tutorial with UITableView
uses EditMode AND storyboards. All tutorials which I have found are based on the "old" Xcode.
非常感谢您
顺便说一下,这是我的代码:
By the way, here is my code:
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
myData = [NSMutableArray arrayWithObjects:
@"Line1_Label1|Line1_Label2|Line1_Label3",
@"Line2_Label1|Line2_Label2|Line2_Label3",
@"Line3_Label1|Line3_Label2|Line3_Label3",
nil];
self.navigationItem.leftBarButtonItem = self.editButtonItem;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [myData count];
}
// Return a cell for the table
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// A cell identifier which matches our identifier in IB
static NSString *CellIdentifier = @"CellIdentifier";
// Create or reuse a cell
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Get the cell label using its tag and set it
NSString *currentItem = [myData objectAtIndex:indexPath.row];
NSArray *itemArray = [currentItem componentsSeparatedByString:@"|"];
UILabel *cellLabel = (UILabel *)[cell viewWithTag:1];
[cellLabel setText:itemArray[0]];
UILabel *cellLabel2 = (UILabel *)[cell viewWithTag:3];
[cellLabel2 setText:itemArray[1]];
UILabel *cellLabel3 = (UILabel *)[cell viewWithTag:4];
[cellLabel3 setText:itemArray[2]];
// get the cell imageview using its tag and set it
UIImageView *cellImage = (UIImageView *)[cell viewWithTag:2];
[cellImage setImage:[UIImage imageNamed: @"control.png"]];
return cell;
}
// Do some customisation of our new view when a table item has been selected
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Make sure we're referring to the correct segue
if ([[segue identifier] isEqualToString:@"ShowSelectedMovie"]) {
// Get reference to the destination view controller
ItemViewController *vc = [segue destinationViewController];
// get the selected index
NSInteger selectedIndex = [[self.tableView indexPathForSelectedRow] row];
// Pass the name and index of our film
[vc setSelectedItem:[NSString stringWithFormat:@"%@", [myData objectAtIndex:selectedIndex]]];
[vc setSelectedIndex:selectedIndex];
}
}
@end
推荐答案
首先,在.h中创建表格视图的IBOutlet,然后在.m中对其进行合成.
First of all, make an IBOutlet of the tableview in the .h and synthesize it in the .m.
然后对编辑"按钮进行操作(如果您还没有的话).在操作中,写:
Then make an action to the edit button (if you don't already have one). In the action, write:
CGRect rect = yourTableView.cell.contentView.frame;
//Do whatever changes you wish to do with the sizing of the view. origin changes placement and size changes size (duh). Line below is an example.
rect.origin.y = yourTableView.cell.contentView.frame.origin.y - 20;
yourTableView.cell.contentView.frame = rect;
这不会动起来,但我认为它将满足您的目的.
This won't be animated, but I think it'll fulfill your purpose.
这篇关于单元格的UITableView内容在编辑时不会移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!