- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发一个 iOS 应用程序,我正在尝试使用自定义 UITableViewCell
实现我自己的自定义 UITableView
编辑模式。
我有一个编辑按钮,这是它的 IBAction:
- (IBAction)editFavList:(id)sender
{
if ([_favList isEditing])
{
[_favList setEditing:NO animated:YES];
[_editButton setTitle:@"Edit" forState:UIControlStateNormal];
}
else
{
[_favList setEditing:YES animated:YES];
[_editButton setTitle:@"Done" forState:UIControlStateNormal];
}
}
我已将 UITableView* _favList
delegate
连接到 UIViewController
并且此 UITableViewDelegate
方法在我点击之前工作正常编辑按钮:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView.editing)
{
NSNumber* obj = [favsSelected objectAtIndex:indexPath.row];
BOOL selected;
if (obj == nil)
selected = NO;
else
selected = [obj boolValue];
FavouriteCell* cell =
(FavouriteCell*)[tableView cellForRowAtIndexPath:indexPath];
cell.checked = !selected;
// Actualizo el estado en el vector de los favoritos seleccionados
[favsSelected insertObject:[NSNumber numberWithBool:!selected] atIndex:indexPath.row];
}
}
点击编辑按钮后,此方法不会触发(我对此很确定,因为我在该方法上添加了一个断点)。
这是自定义单元实现:
#import "FavouriteCell.h"
const NSInteger EDITING_HORIZONTAL_OFFSET = 35;
@implementation FavouriteCell
@synthesize selectIcon = _selectIcon;
@synthesize favName = _favName;
@synthesize checked = _checked;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.checked = NO;
}
return self;
}
- (void)setChecked:(BOOL)checked
{
if (checked == _checked)
return;
_selectIcon.highlighted = checked;
_checked = checked;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
+ (NSString *)reuseIdentifier
{
return @"favouriteCell";
}
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
//self.editing = editing;
[super setNeedsLayout];
}
#pragma mark - Private methods
- (void)layoutSubviews
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[super layoutSubviews];
if (((UITableView *)self.superview).isEditing)
{
CGRect contentFrame = self.contentView.frame;
contentFrame.origin.x = EDITING_HORIZONTAL_OFFSET;
self.contentView.frame = contentFrame;
self.accessoryType = UITableViewCellAccessoryNone;
}
else
{
CGRect contentFrame = self.contentView.frame;
contentFrame.origin.x = 0;
self.contentView.frame = contentFrame;
self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
[UIView commitAnimations];
}
@end
但是如果我再次点击编辑按钮(然后,我离开编辑模式),如果我点击一行,didSelectRowAtIndexPath
会再次触发。
为什么我做错了?这个问题可能与 UITableView
是否处于编辑模式有关。
最佳答案
检查 nib 文件。您应该将 tableView editing
属性更改为 Single Selection during editing
。
关于ios - 在 UITableView 编辑模式下,UITableView :didSelectRowAtIndexPath: doesn't respond,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14892445/
我需要在 didSelectRowAtIndexPath 方法内部再次调用 UITableView 中的 didSelectRowAtIndexPath 方法。 代码如下: -(void)tableV
我正在尝试在单元格创建 cellForRowAt 中手动调用 didSelectRowAtIndexPath,因为这将更新详细 View 而无需实际触摸该行,但是当我这样做时所以我在实际委托(dele
出于某种原因,我无法在以下代码中的第一个 IF 语句之后访问任何变量。例如,如果索引路径为[0,0],则变量phoneText 会输出电话号码。但如果它是 [1,0] 或 [2,0],我会得到“nul
我知道之前提到过这个问题,但那里的解决方案并不适用。我有一个使用 IB 设置的带有嵌入式 UITableViewController 的 UINavigationController 。在IB中,UI
我遇到了 ios 5 的 UITableView 的 didSelectRowAtIndexPath 问题,这在 ios 4 中是正确的。 第一次点击表中的任何行时,不会调用该方法。一旦我选择另一行,
我有一个 Viewcontroller,它是 UITableViewController 的子类。基本上我的问题是当我们点击主按钮时委托(delegate)方法被调用: - (void)tableVi
我在 uitextfield 正下方有一个 uitableview,它在 uitableview 单元格 中填充类似的字符串。项目被填充。但是,长按后会调用 didSelectRowAtIndexPa
所以我试图默认在我的 View 首次加载时选择 tableView 中的第一行。我正在这样做我的 viewWillAppear 方法: NSIndexPath *tempPath= [NSIndexP
我想在某个条件不满足时中止这个方法,我该怎么做? 我不使用 tableView:willSelectRowAtIndexPath: 方法。我认为可以结合这两种方法来防止某些行被选择并被推送到另一个 V
我有一个分为2个部分的UItableView。 我如何管理tableView didSelectRowAtIndexPath方法? 对于第1部分,该方法正在运行,但是对于第二部分,我不知道如何实现。
在我的应用执行期间的各个时间点,都需要使用以下命令以编程方式选择UITableView的一行 [self.tableView selectRowAtIndexPath:selectedCellInde
我有一个自定义的 UITableViewCell,其中包含一些 TextView 和一个 ImageView 。这些 View 是不可选择的(在 IB 中设置)。我希望当用户点击单元格内的任意位置时触
我用它创建了一个表和一个搜索栏 Controller 。我使用了一个结构来创建表内容。我只想将所选单元格中的数据存储在变量中。我是一名新的 iOS 开发人员。请帮忙:) TIA //my struct
我在表格 View 中有 5 个自定义单元格,但 didSelectRowAtIndexPath 仅适用于一个单元格。我已在代码中该单元格的索引处添加了该行的单元格。 let cell : FileS
我现在正在弄乱 table ,我的目标是最终能够点击 table 并转到某个地方。但是,我无法使 didSelectRowAtIndexPath 工作。该表显示正常,但当我选择它时没有任何反应: cl
didSelectRowAtIndexPath:即使在将表委托(delegate)和数据源连接到文件所有者后,方法也不会调用。 当我试图打印一些东西时,它没有用这种方法打印 在下面找到我的代码供您引用
我在 viewController 中有两个 UITableView。两者都有不同的标签。带有标签 0 的 UITableview 是可编辑的,而标签 1 是不可编辑的。我的问题是当在带有标签 1 的
我正在尝试学习在我的应用程序中使用核心数据。我怎么会被困在这里 didSelectRowAtIndexPath 如果可能的话,我希望能够像以前一样使用我的 uitableview arrayA 是一个
我有一个 UITableView,其中填充了 30 多个 UITableviewCell。 我面临的问题是,当选择一行并更改单元格的 accessoryType 时,该行的第十一行也会被修改。 我已经
在我的 UITableView 中,我有 2 行。我正在尝试禁用第二行,因此我完成了图片中显示的以下操作。当我运行该程序时,虽然该行无法推送到另一个 View ,但当我单击它时蓝色突出显示仍然闪烁。
我是一名优秀的程序员,十分优秀!