gpt4 book ai didi

iphone - editingStyleForRowAtIndexPath 同时调用了三次。为什么?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:25:12 27 4
gpt4 key购买 nike

我有一个 TableView,每行有两个 UILabel。当用户在单元格上滑动时,我想减少单元格上第一个标签的框架,以解决此问题:

bug_image

这是我的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NO] autorelease];
}

custom_cell = [[[UILabel alloc] initWithFrame:CGRectMake(10, 0, 200, 45)] autorelease];


custom_cell.textColor = [UIColor blackColor];

custom_cell.backgroundColor = [UIColor clearColor];

[custom_cell setText:[[self.Notes objectAtIndex:indexPath.row ]objectForKey:@"Text"]];

[cell.contentView addSubview:custom_cell];

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat: @"dd MMM yy"];

[dateFormat setLocale:[NSLocale currentLocale]];

NSDate *dateTmp = [[self.Notes objectAtIndex:indexPath.row] objectForKey:@"CDate"];

cell.detailTextLabel.text = [dateFormat stringFromDate: dateTmp];

cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

[dateFormat release];

return cell;


}

然后,为了减少我单元格上第一个标签的框架,我编写了这段代码:

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {

NSLog(@"row=%d", indexPath.row);

custom_cell.frame = CGRectMake(10, 0, 150, 45);

return UITableViewCellEditingStyleDelete;
}

结果部分正确。我的 tableView 的最后一个标签总是缩小,而不是正确的。

控制台还会打印三次 NSLog 消息。为什么?

2012-06-13 22:07:34.809 myVoyager[1935:16103] row=0
2012-06-13 22:07:34.810 myVoyager[1935:16103] row=0
2012-06-13 22:07:34.813 myVoyager[1935:16103] row=0

谢谢,来自比萨的亚历山德罗(抱歉我的英语不好!)

最佳答案

我是来自比萨的 Valerio!您应该在 editingStyleForRowAtIndexPath 方法中这样做:

UITableViewCell *myCell = [self.tableView cellForRowAtIndexPath:indexPath];

然后给cell设置frame。

关于iphone - editingStyleForRowAtIndexPath 同时调用了三次。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11022876/

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