小编lam*_*ade的帖子

为什么我的表视图没有调用委托方法?

我正在构建基于文档的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)

cocoa

1
推荐指数
1
解决办法
1554
查看次数

这个' - >'在c/objective-c中意味着什么?

我正在查看一些代码,我遇到了一些我不知道的含义的语法.' - >'是什么意思?

-(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)

c syntax objective-c

1
推荐指数
1
解决办法
1637
查看次数

我正在尝试在Objective C中构建一个待办事项列表应用程序但是很简单

我收到这个错误: -[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)

cocoa objective-c

0
推荐指数
1
解决办法
730
查看次数

我的代码不是主要的

我试图理解为什么我的应用程序不会离开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)

cocoa-touch objective-c

0
推荐指数
1
解决办法
127
查看次数

为什么收集和每个方法与succ方法的工作方式不同?

["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方法递增一个字符串.

ruby

0
推荐指数
1
解决办法
64
查看次数

How does "unless" work in Ruby?

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?

ruby

-2
推荐指数
1
解决办法
792
查看次数

标签 统计

objective-c ×3

cocoa ×2

ruby ×2

c ×1

cocoa-touch ×1

syntax ×1