【问题标题】:NSTableView's row numberNSTableView 的行号
【发布时间】:2011-06-20 15:46:14
【问题描述】:

我找不到让一行显示显示行号的方法。

事实上,我有一个NSArrayController 和一个NSTableView,它们的列绑定到NSArrayController

现在我必须显示行号(也许 DataModel 中数据的索引很好),但我找不到这样做的方法。

有什么建议吗?

【问题讨论】:

    标签: objective-c cocoa macos nstableview nsarraycontroller


    【解决方案1】:

    【讨论】:

    • 感谢您的回复,我看到了这个答案,但对我没有多大帮助。我认为可以使用像arangedObjects.@cound.propertyName 这样的NSArrayController` 方法来计算实体的行数,然后将行的列绑定到它包含的数组,其中包含从1@count 的数字。你怎么看?
    • 老实说,我会说忘记绑定该行。我的意思是,除非您在实体中跟踪它,否则您甚至会将它绑定到什么?您实际上是该链接中提到的数据源方法吗?如果您反对,那么您需要做的是向您的实体添加一个属性(即 rowIndex)。但是您会发现很难使该属性与现实保持同步,除非您的数据非常静态。
    • 你说得对,我的朋友,我的意思是显示从1@count 的行,但我说错了BIND。是否可以分配表格的列单元格以显示一些特殊的 NSNumber?
    • 是的,这是可能的。您所要做的就是按照我链接到的答案中的说明进行操作。如果您查看已接受的答案,原始海报会留下评论,解释如何执行此操作。你为什么不想尝试呢?
    • 我可以重新打开这个问题吗?我需要在使用 NSOrderedSet 类的有序核心数据关系中显示对象的索引。与引用的问题相反,#I want to display 不是显示索引,而是关系中的对象索引。它们通常相同,但并非总是相同,例如在过滤掉某些行时。
    【解决方案2】:

    在接口生成器中绑定 object.value 的示例:

    // InfoToBind.h

    @interface InfoToBind : NSObject {
    
    NSString *kSurname ;
    NSString *kName ;  
    NSInteger kNumberRow;  
    }
    @property (nonatomic, retain) NSString * kSurname ;
    @property (nonatomic, retain) NSString *kNameKey ;
    @property (nonatomic, assign) NSInteger kNumberRow;
    

    //InfoToBind.m

    @syntesize ...
    

    //delegate.m

    #import "InfoToBind.m
    
    
    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
    {
    
    InfoToBinb *infoBind = [InfoToBind alloc]init];
    
    images = [[NSMutableArray alloc]init];
    
    
    //example
    InfoDictionary = [[NSDictionary alloc] initWithObjectsAndKeys: 
        @"name", @"Giulio", @"surname", @"Cesare", nil];
    
    NSMutableArray dataSourceArray = [NSMutableArray alloc]init];
    
    infoBind.kName = [InfoDictionary objectForKey:@"Name"];
    infoBind.kSurname = [InfoDictionary objectForKey:@"Surname"];
    
     NSUInteger x;
     for (x = 0; x <= dasourceArray.count; x++) {
        infoBind.kNumberRow ++;
     }
     [dataSourceArray addObject:myClass];
    
    
    [_tableView insertRowsAtIndexes:[NSIndexSet indexSetWithIndex:dataSourceArray.count]   withAnimation:NSTableViewAnimationSlideLeft];
    
     }
    
    - (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView{
    
    return [dataSourceArray count];
    }
    
    - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
    // Used by bindings on the NSTableCellView's objectValue
    NSDictionary *item = [dataSourceArray objectAtIndex:row];
    NSLog(@"item is %@", item);
    
    return item;
    

    }

    //在CellView中拖一个TextField,绑定到“表格单元格视图”,加上这个值:objectValue.kNumberRow

    【讨论】:

      猜你喜欢
      • 2015-05-25
      • 1970-01-01
      • 1970-01-01
      • 2011-01-13
      • 2021-09-13
      • 1970-01-01
      • 2010-10-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多