English 中文(简体)
表格 观点 说明 DidChange:不叫
原标题:tableView sortDescriptorsDidChange: not getting called

贺词,

我有两栏可读书,可作罚款......除非: 如果我确定接口建设者的表格的描述,则按预期进行工作,并按预期进行描述。 但是,如果I don t在Interface Buildinger中设置了描述,而是使用:

[tableView setSortDescriptors:[NSArray arrayWithObject:[[[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES selector:@selector(caseInsensitiveCompare:) ]autorelease]]];

(如果“姓名”是左栏的识别符号),则打字 DidChange从未得到援引。 我读(已读?) 我认为,NSTableView的 Apple果文件应该发挥作用。 我做了什么错误?

P.S.,我知道,我还可以为此使用一架国家航空航天局的主计长(如果我这样做的话,会打上罚款),但出于任何原因,我选择不这样做。

问题回答

它应当不这样做,但你是否试图寄送KVO通知?

[tableView willChangeValueForKey:@"sortDescriptors"];
[tableView setSortDescriptors:[NSArray arrayWithObject:[[[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES selector:@selector(caseInsensitiveCompare:) ]autorelease]]];
[tableView didChangeValueForKey:@"sortDescriptors"]; 

如果您不希望加入国际律师协会的描述者,你可以做这样的事情。

- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)theColumn row:(NSInteger)rowIndex {
    //if we have no sort descriptor for this column create one based on it s identifier (instead of setting it for each in IB,saves time and prevents errors)
    NSSortDescriptor *desc = [theColumn sortDescriptorPrototype];
    if ([desc key] == nil) {
        NSSortDescriptor *sorter = [[NSSortDescriptor alloc] initWithKey:[theColumn identifier] ascending:YES];  
        [theColumn setSortDescriptorPrototype:sorter];
        [sorter release];
    }
}




相关问题
How do I sort enum members alphabetically in Java?

I have an enum class like the following: public enum Letter { OMEGA_LETTER("Omega"), GAMMA_LETTER("Gamma"), BETA_LETTER("Beta"), ALPHA_LETTER("Alpha"), private final String ...

Grokking Timsort

There s a (relatively) new sort on the block called Timsort. It s been used as Python s list.sort, and is now going to be the new Array.sort in Java 7. There s some documentation and a tiny Wikipedia ...

Sorting twodimensional Array in AS3

So, i have a two-dimensional Array of ID s and vote count - voteArray[i][0] = ID, voteArray[i][1] = vote count I want the top 3 voted items to be displayed in different colors, so i have a 2nd Array -...

Linq operations against a List of Hashtables?

I m working with a set of legacy DAO code that returns an IList, where each Hashtable represents the row of a dynamically executed SQL query. For example, the List might contain the following records/...

C++ Array Sort Me

Stuck on an array sorter. Have to sort numbers from largest to smallest. I m trying two loops (one nested in the other). Here s the code: int counter=0; // inner counter int counter2=0; // outer ...

Can I Nest OrderBy in .NET?

This doesn t seem to work as I intend. VB.NET: Dim x = Model.Discussions.OrderByDescending(Function(d) d.Messages.OrderByDescending(Function(m) m.Sent).First.Sent) For Each d As Discussion In x ....

sorting elements javascript

I m looking for a way to sort my elements, but it isn t as easy as it sounds. Please let me explain My elements are grouped per 6 elements (thumbnails), each x represents a thumbnail However all ...

热门标签