这可能是设计不佳造成的,但是当我滚动表格太快,然后滚动回顶部时,放置在最后一个表格单元格中的视图也放置在 tableView 中的第一个表格单元格上。
我觉得可能是我用if语句把一些静态内容放在第一部分,动态内容放在第二部分造成的。
任何帮助表示赞赏。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
if (indexPath.section == 0) {
if (indexPath.row == 0) {
cell.selectionStyle = UITableViewCellSelectionStyleNone;
UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(10, 13, 282, 20)];
textField.clearsOnBeginEditing = NO;
textField.placeholder = @"enter template name";
textField.font = [UIFont systemFontOfSize:15.0];
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.delegate = self;
textField.text = [selectedTemplate name];
[textField addTarget:self action:@selector(nameDidChange:) forControlEvents:UIControlEventEditingChanged];
[cell.contentView addSubview:textField];
} else {
cell.textLabel.text …Run Code Online (Sandbox Code Playgroud) 我想QTreeWidget按alpha_numeric专栏排序.
更新:
按照ekhumoro的例子,我重新实现了QTreeWidgetItem __lt__使用所需自然排序的方法.
相关代码:
class TreeWidgetItem(QtGui.QTreeWidgetItem):
def __lt__(self, other):
column = self.treeWidget().sortColumn()
key1 = self.text(column)
key2 = other.text(column)
return self.natural_sort_key(key1) < self.natural_sort_key(key2)
@staticmethod
def natural_sort_key(key):
regex = '(\d*\.\d+|\d+)'
parts = re.split(regex, key)
return tuple((e if i % 2 == 0 else float(e)) for i, e in enumerate(parts))
Run Code Online (Sandbox Code Playgroud)
更新完整的工作示例:
import sys
import re
from PySide import QtGui, QtCore
data = [
{"name": "Apple", "alpha_numeric": "11"},
{"name": "Apple", "alpha_numeric": "125b"},
{"name": …Run Code Online (Sandbox Code Playgroud)