开发者

How to change an NSTableView's selection without using deprecated methods

I have the Apress "Learn Cocoa" book (published in 2010 BTW) and I am getting a deprecation error on one of the lines. The code is:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    self.villain = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Lex Luthor", kName, @"Smallville", kLastKnownLocation, [NSDate date], kLastSeenDate, @"Superman", kSwornEnemy, @"Revenge", kPrimaryMotivation, [NSArray arrayWithObjects:@"Intellect", @"Leadership", nil], kPowers, @"Superhero Action", kPowerSource, [NSNumber numberWithInt:9], kEvilness, [NSImage imageNamed:@"NSUser"], kMugshot, @"", kNotes, nil];
    self.villains = [NSMutableArray arrayWithObject:self.villain];
    [villainsTableView reloadData];
    [villainsTableView selectRow:0 byExtendingSelection:NO];
    [self updateDetailViews];
}

I am getting the error on the 2nd to last line and I don't know exactly what that line is intending to 开发者_JAVA技巧do.


The replacement for the deprecated method would look like this:

[villainsTableView selectRowIndexes:[NSIndexSet indexSetWithIndex:0] byExtendingSelection:NO];


The documentation tells you what that message does and what the replacement is.


In XCode you can place the mousecursor above the symbol you want to know something about. While placing the mousecursor above this symbol (i.e. NSString), hold down the ALT-Key and doubleclick. This will open up a context sensitive documentation. All deprecated methods and symbols are marked red there. Mostly the new replacement is documented next to the old one. In the new xcode, a popup-window will appear. The doc will be opened by clicking the "notebook"-icon at the border of the box.

i.e. for NSString you will find:
– initWithCString: Deprecated in iOS 2.0
+ stringWithCString:encoding:

With an educated guess you will choose "+ stringWithCString:encoding:" Apple almost adds new functionality which is a logical augmentation of the old stuff, so you don't need to google hard, but watch into the method summary of the related doc.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜