- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图同时绑定(bind)两个 Action 。其中之一动态更改 heighForRow
,第二个动态地拉伸(stretch) View.frame。两者都通过相同的点击被解雇。问题是当我尝试添加 reloadRowsAtIndexPath
触摸后,当行高发生变化时,不幸的是行标题和颜色“乱七八糟”。例如,在触摸第二行的位置后,第一行显示,第三行显示第一行,每次单击依此类推但是更改 rowHeight 有效!并且日志显示正确的行被触摸 - (所以当我触摸第一个时,第一个用 NSLog 记录)。有什么想法吗?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil){
cell = [[PrototypeCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
[cell setBackgroundColor:[UIColor clearColor]];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
[cell setIndentationWidth:0.0];
PrototypeCell *prototypeCell =(PrototypeCell *)cell;
prototypeCell.View = [[UIView alloc]init];
prototypeCell.View.frame = CGRectMake(0,0, 15, 120);
prototypeCell.View.alpha = .5f;
[cell addSubview:prototypeCell.View];
DetailView *detailView = [[DetailView alloc] initWithFrame:CGRectMake(0, 120, 320, 120)];
[cell addSubview:detailView];
prototypeCell.detailView = detailView;
if (indexPath.row == 0){
prototypeCell.View.backgroundColor = [UIColor redColor];
cell.textLabel.text = [self.thingList objectAtIndex:indexPath.row];
}
if (indexPath.row == 1){
prototypeCell.View.backgroundColor = [UIColor greenColor];
cell.textLabel.text = [self.thingList objectAtIndex:indexPath.row];
}
if (indexPath.row == 2){
prototypeCell.View.backgroundColor = [UIColor blueColor];
cell.textLabel.text = [self.thingList objectAtIndex:indexPath.row];
}}
cell.textLabel.font = [UIFont boldSystemFontOfSize:21];
cell.detailTextLabel.font = [UIFont italicSystemFontOfSize:13];
cell.accessoryType = UITableViewCellAccessoryNone;
PrototypeCell *prototypeCell =(PrototypeCell *)cell;
prototypeCell.detailView.hidden = !expanded[indexPath.row];
return cell;
}
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
int selectedRow = indexPath.row;
NSLog(@"touch on row %d ", selectedRow);
PrototypeCell *prototypeCell =(PrototypeCell *)[tableView cellForRowAtIndexPath:indexPath];
[self.tableView beginUpdates];
expanded[indexPath.row] = !expanded[indexPath.row];
[tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];
if (prototypeCell.stretched == NO){
[UIView animateWithDuration:1 animations:^{
prototypeCell.View.frame = CGRectMake(0, 0, 320, 120);
}
completion:nil];
prototypeCell.stretched = YES;
}
else {
[UIView animateWithDuration:1 animations:^{
prototypeCell.View.frame = CGRectMake(0, 0, 15, 120);
}
completion: nil];
prototypeCell.stretched = NO;
}
}
最佳答案
问题在于您如何使用 dequeueReusableCellWithIdentifier,因为当单元格被重用时,您的以下代码将不会执行。
if (indexPath.row == 0){
prototypeCell.View.backgroundColor = [UIColor redColor];
cell.textLabel.text = [self.thingList objectAtIndex:indexPath.row];
}
if (indexPath.row == 1){
prototypeCell.View.backgroundColor = [UIColor greenColor];
cell.textLabel.text = [self.thingList objectAtIndex:indexPath.row];
}
if (indexPath.row == 2){
prototypeCell.View.backgroundColor = [UIColor blueColor];
cell.textLabel.text = [self.thingList objectAtIndex:indexPath.row];
}
此代码仅在您的单元格为 nil 时执行,如果您不想重用单元格,则必须将此代码移出 nil block ,否则如果您的单元格有限并且每个单元格都不同,请不要重用。
完成动画后,也将这两行移到最后
[tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];
关于ios - reloadRowsAtIndexPaths 搞乱了 animateWithDuration,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33689704/
这段代码的问题(在 func tableView(tableView: UITableView, commitEditingStyleeditingStyle: UITableViewCellEdit
我有一个分组 TableView ,我想在其中重新加载特定行。当我调用 reloadRowsAtIndexPaths: 时,该行从 TableView 中完全消失。我还需要做其他事情吗? //this
我将 UITableView 与静态单元格一起使用。如果我使用reloadData,那么一切都OK。 如果我尝试reloadRowsAtIndexPaths它会隐藏行。如果我上下拖动 tableVie
我看过很多这样的代码,但不确定如何实际实现它。 [self.tableView beginUpdates]; [self.tableView reloadRowsAtIndexPaths:@[inde
我有一个 UITableView,它的数据源通过调用 PHP 脚本得到更新,如果有任何数据要更新,响应会向数组添加一个新对象。如果通过 TimeStamp 添加了新项目,并且如果有新数据,那么新数据将
在我的应用程序中,当像这样重新加载表格 View 单元格时 let editItemView = view.viewWithTag(12) as! UITableView let indexPath
我正在尝试在我的 UITableCells 上添加赞成票和反对票 我的意思是: 每当我点击向上和向下按钮时,它应该立即更新单元格 这是我填充表格的方式: 我的 UITableView 中的代码块 ..
我有一个分页 tableView,每次用户滚动时都会加载一个新页面,有点像 instagram 提要。 tableView 的重新加载发生在获取新页面后的回调中。代码看起来像这样: func fetc
我有一个表格 View 。每个单元格每 10 秒更新一次。每个单元格都有 editActions,例如: 但是当我向左滑动以查看操作时,同时调用 reloadRowsAtIndexPaths 函数时,
我的 ViewController 中有一个 UITableView。其中一个单元格可以接入另一个 TableViewController 以允许选择一个值。 我想在从被调用者 ViewControl
我正在尝试覆盖 tableView 单元格的方法 reloadRowAtIndexPath。 我想做的和你覆盖 cellForRowAtIndexPath 时一样: func tableView(ta
我正在尝试重新加载单个 tableViewCell,但每次我这样做时它都会滚动到顶部...我没有添加或删除单元格,我只是想更改所选单元格的颜色。 这就是我在 cellForRowAtIndexPath
我在我的 iOS 应用程序中使用 UITableView,最近遇到了一个奇怪的问题。 假设我的表结构如下: section 1 header row section 2 header section
我有一个表格 View ,其中每个单元格都包含播放音频文件的功能。我正在尝试复制在语音备忘录程序中找到的单元格: 我正在使用 UISlider 提供播放栏,并且我有当前时间和剩余时间的文本标签。我希望
我有一个 UITableview,可以延迟加载所有不同大小的图像。加载图像时,我需要更新特定的单元格,因此我发现我需要使用 reloadRowsAtIndexPaths。但是当我使用这个方法时,它仍然
我正在尝试使用按钮删除单元格。 这是单元格的实现。 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRo
我有一个 UITableView,其中包含一个包含 UIWebView 的自定义单元格。一旦 webview 完成加载 html 内容,我就会尝试以正确的高度重新加载单元格。 override fun
背景:在 tableView 中,每个单元格都包含一个显示为图像的按钮。我想展示的效果是,当我点击图片(实际上是按钮)时,按钮的图片会变成另一个图片。 错误:假设有很多数据(超过一页),如果我点击一个
我试图同时绑定(bind)两个 Action 。其中之一动态更改 heighForRow,第二个动态地拉伸(stretch) View.frame。两者都通过相同的点击被解雇。问题是当我尝试添加 re
我有一个 tableviewcell在RegisterViewController ,当我点击它时,它会推送到 SelectCityViewController我可以从 uipickerview 中选
我是一名优秀的程序员,十分优秀!