【问题标题】:tableviewcell does not contains UITableViewCellReorderControl in iosios中的tableviewcell不包含UITableViewCellReorderControl
【发布时间】:2015-01-22 15:01:56
【问题描述】:

我想重新定位默认显示在行右侧的 tableviewcell 的重新排序栏。所以我尝试了this link 但是当我记录子视图时,UITableViewCellReorderControl 根本不存在。但是当我设置时:

[self setEditing:YES];
[tableView setEditing:YES]; 

如果出现在右侧。

到目前为止我的方法:

- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    for(UIView* view in cell.subviews)
    {
         NSLog(@"Tableview subviews: %@",[[subviewCell class] description]);
    }
}

for(UIView* subviewCell in cell.contentView.subviews)
{
   NSLog(@"Tableview subviews: %@",[[subviewCell class] description]);
}

但第一个日志:

Tableview subviews: UITableViewCellContentView
Tableview subviews: _UITableViewCellSeparatorView
Tableview subviews: UITableViewCellContentView
Tableview subviews: _UITableViewCellSeparatorView

第二个代码日志:

Tableview subviews: UIImageView
Tableview subviews: UIImageView
Tableview subviews: UIImageView
Tableview subviews: UITextField
Tableview subviews: UIImageView
Tableview subviews: UIImageView
Tableview subviews: UIImageView
Tableview subviews: UITextField

没有 UITableViewCellReorderControl 的迹象。我做错了什么?

【问题讨论】:

    标签: ios uitableview


    【解决方案1】:

    覆盖UITableviewCellsetEditing: animated: 方法。所以,当你的UITableView 进入编辑模式时,它会调用这个方法。

    - (void) setEditing:(BOOL)editing animated:(BOOL)animated
    {
        [super setEditing: editing animated: YES];
    
        if (editing) {
    
           UIView* reorderControl = [cell huntedSubviewWithClassName:@"UITableViewCellReorderControl"];
           NSLog(@"%@", reorderControl);
           [reorderControl setBackgroundColor:[UIColor redColor]];
        }   
    }
    

    更多详情,请转至UITableViewCell class reference

    【讨论】:

    • 我声明了MyTableCell *cell = (MyTableCell*)[editTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];,但它给出了 huntedSubviewWithClassName 的错误,例如No visible @interface for 'MyTableCell' declares the selector huntedSubviewWithClassName:
    猜你喜欢
    • 1970-01-01
    • 2016-05-26
    • 1970-01-01
    • 1970-01-01
    • 2012-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多