我正在构建基于文档的Mac应用程序.我有两个类myDocument和Person.我遇到的困难是当我按下按钮在表视图中添加一个新Person并显示它时它不会在表视图中显示.我已将日志语句放在委托方法中.由于我的日志语句没有显示在控制台中,我知道它们没有被调用.以下是委托方法的实现
- (int)numberOfRowsInTableView:(NSTableView *)aTableView
{
return [employees count];
}
- (id)tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn
row:(int)rowIndex
{
// What is the identifier for the column?
NSString *identifier = [aTableColumn identifier];
NSLog(@"the identifier's name is : %s",identifier);
// What person?
Person *person = [employees objectAtIndex:rowIndex];
// What is the value of the attribute named identifier?
return [person valueForKey:identifier];
}
- (void)tableView:(NSTableView *)aTableView
setObjectValue:(id)anObject
forTableColumn:(NSTableColumn *)aTableColumn
row:(int)rowIndex
{
NSString *identifier = [aTableColumn identifier];
Person *person = [employees objectAtIndex:rowIndex];
NSLog(@"inside the setObjectMethod: %@",person);
// …Run Code Online (Sandbox Code Playgroud) 我正在查看一些代码,我遇到了一些我不知道的含义的语法.' - >'是什么意思?
-(void) getTransformValues:(struct transformValues_*) tv
{
tv->pos = positionInPixels_;
tv->scale.x = scaleX_;
tv->scale.y = scaleY_;
tv->rotation = rotation_;
tv->skew.x = skewX_;
tv->skew.y = skewY_;
tv->ap = anchorPointInPixels_;
tv->visible = visible_;
}
Run Code Online (Sandbox Code Playgroud) 我收到这个错误: -[NSCFArray insertObject:atIndex:]: attempt to insert nil
这是.m文件:
/*
IBOutlet NSTextField *textField;
IBOutlet NSTabView *tableView;
IBOutlet NSButton *button;
NSMutableArray *myArray;
*/
#import "AppController.h"
@implementation AppController
-(IBAction)addNewItem:(id)sender
{
myArray = [[NSMutableArray alloc]init];
tableView = [[NSTableView alloc] init];
[tableView setDataSource:self];
[textField stringValue];
NSString *string = [[NSString alloc] init];
string = [textField stringValue];
[myArray addObject:string];
NSLog(@"%d",[myArray count]);
NSLog(@"%@",string);
}
- (int)numberOfRowsInTableView:(NSTableView *)aTableView
{
return [myArray count];
}
- (id)tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn
row:(int)rowIndex
{
//NSString *data = [myArray objectAtIndex:rowIndex];
return [myArray objectAtIndex:rowIndex];
} …Run Code Online (Sandbox Code Playgroud) 我试图理解为什么我的应用程序不会离开main(启动).我认为这条线是原因.
int retVal = UIApplicationMain(argc, argv, nil , nil);
Run Code Online (Sandbox Code Playgroud)
源代码:
#import <UIKit/UIKit.h>
int main(int argc, char *argv[])
{
printf("I'm in main");
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
printf("\nafter the autiorealeas pool");
int retVal = UIApplicationMain(argc, argv, nil , nil);
printf("\nbefore the [pool relase] call");
[pool release];
printf("Leaving main");
return retVal;
}
Run Code Online (Sandbox Code Playgroud) ["H", "A", "L"].collect {|x| x.succ } # => ["I", "B", "M"] 但
["H", "A", "L"].each {|x| x.succ } # => ["H", "A", "L"]
Run Code Online (Sandbox Code Playgroud)
造成输出差异的原因是什么?
该succ方法递增一个字符串.
I would like to refactor:
def play_as_dealer
if value < 16
hit!(deck)
play_as_dealer
end
end
Run Code Online (Sandbox Code Playgroud)
to this version
def play_as_dealer
hit!(deck) unless value > 16
play_as_dealer
end
Run Code Online (Sandbox Code Playgroud)
My version with the unless statement does not work. Why is that?