作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个 TableView,每行有两个 UILabel。当用户在单元格上滑动时,我想减少单元格上第一个标签的框架,以解决此问题:
这是我的代码:
- (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/
我必须使用哪种 editingStyle 才能获得本教程的结果? Table View Programming 我想要一个不带“-”或“+”的 editingStyle。如果在方法 editingSt
我有一个 TableView,每行有两个 UILabel。当用户在单元格上滑动时,我想减少单元格上第一个标签的框架,以解决此问题: 这是我的代码: - (UITableViewCell *)table
我花了几个小时努力将滑动删除功能添加到我的应用程序中的普通 UITableView 但没有成功。 我有一个 UIViewController,其中唯一包含一个 UITableView,它使用基本单元格
我是一名优秀的程序员,十分优秀!