小编Col*_*ole的帖子

NSOpenPanel - 一切都弃用了吗?

我一直试图让一个窗口显示要求该人选择一个文件,我最终做到了.问题是,Xcode抱怨我正在使用的方法已被弃用.我查看了类引用,但从Mac OS 10.6开始,"运行面板"部分下的所有内容都已弃用.我现在应该使用不同的课吗?

macos cocoa nsopenpanel

12
推荐指数
3
解决办法
1万
查看次数

使用Xcode 4在Mac OS X Lion上设置SDL

我一直试图让一个超级简单的SDL程序工作.我正在使用Mac OS X Lion.我有SDL在Snow Leopard工作,但它似乎不想在狮子身上工作.到目前为止我有这个:

#include <iostream>
#include "SDL/SDL.h"

using namespace std;

/*
#ifdef main
#  undef main
#endif
*/

int main( int argc, char* args[] )
{
    SDL_Surface* hello = NULL;
    SDL_Surface* screen = NULL;
    SDL_Init( SDL_INIT_EVERYTHING );
    screen = SDL_SetVideoMode( 640, 480, 32, SDL_SWSURFACE );
    hello = SDL_LoadBMP( "hello.bmp" );
    SDL_BlitSurface( hello, NULL, screen, NULL );
    SDL_Flip( screen );
    SDL_Delay( 2000 );
    SDL_FreeSurface( hello );
    SDL_Quit();

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

当我尝试编译此代码时(在Xcode 4.1中),它给了我这个错误:

Undefined symbols for architecture x86_64:
  "_main", referenced …
Run Code Online (Sandbox Code Playgroud)

macos sdl xcode4 osx-lion

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

为UIViewController制作一个委托

我看了一遍,发现很多人有类似的问题,但我仍然无法让我的代表工作.我想弹出一个模型视图控制器,然后在视图中调用一个方法,使模型视图要求它解除它.所以我有这条线:

mergeConfig *view = [[mergeConfig alloc] initWithNibName:@"mergeConfig" bundle:nil];
Run Code Online (Sandbox Code Playgroud)

我试图[view setDelegate:self];以在上述苹果的开发者页面,但我expectably模型视图没有setDelegate方法.

所以我想知道的是,我如何获得它以便我可以设置一个委托?然后,一旦我这样做,它是否只是自动将调用方法调用到父视图中具有相同名称的方法?Apple的页面没有说明要在模型视图控制器中放入什么代码.

iphone model-view-controller delegates

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

CGContextFillRect没有绘制矩形?

我有这个代码:

CGColorRef darkColor = [[UIColor colorWithRed:21.0/255.0 green:92.0/255.0 blue:136.0/255.0 alpha:1.0] CGColor];
CGContextRef context = UIGraphicsGetCurrentContext(); 
CGContextSetFillColorWithColor(context, darkColor);
CGContextFillRect(context, CGRectMake(18, 62, 66, 66));
Run Code Online (Sandbox Code Playgroud)

我只是将它放在我视图的viewdidload方法中,但我的视图看起来与之前没有任何不同.我试过让它变得非常大而且明亮的红色,但它只是没画画.我需要一些其他初始化代码吗?

编辑:在给出给我的答案后,我现在在我的veiwdidload中有这个:

[self.view addSubview:[[[imageBackground alloc] init] autorelease]];
Run Code Online (Sandbox Code Playgroud)

并在imageBackground.m中:

@implementation imageBackground

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        self.opaque = YES;
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}


// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    CGColorRef darkColor = [[UIColor …
Run Code Online (Sandbox Code Playgroud)

iphone core-graphics

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

在Meteor中存储每用户数据

我想在我的流星应用程序中存储每个登录用户的信息,例如他们的个人资料图片,生物等.但是,如果我尝试做像Meteor.user()那样的事情.picLink ="..."; 它似乎在每次后续调用Meteor.user()时被删除.我认为这意味着我不应该直接在用户对象上存储额外的数据.

我能想到的唯一回应是在其中包含一个包含用户数据的单独集合.但这似乎很难与Meteor.users保持一致.有没有更好的办法?

data-modeling meteor

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

NSArray早早发布

当我向下滚动UITableView时,我的iPhone应用程序崩溃了.我将NSZombieEnabled设置为YES,并发现我用来填充表的NSArray正在以某种方式被释放.

#import "RootViewController.h"

@implementation RootViewController
@synthesize flashsets;

- (void)viewDidLoad
{
        //Unrelated code removed from this post
        NSString *listofsetsstring = [[NSString alloc]
                                          initWithContentsOfFile:pathtosetsdata
                                          encoding:NSUnicodeStringEncoding
                                          error:&error];
        flashsets = [listofsetsstring componentsSeparatedByString:@"\n"];
        [super viewDidLoad];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [flashsets count];
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

    }

    // Configure …
Run Code Online (Sandbox Code Playgroud)

iphone memory-management nsarray

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

NSString.length给出了EXC_BAD_ACCESS

我有以下代码:

NSArray *array = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil];

NSString *temp;
for (int i = 0; i < [array count]; i++)
{
    temp = [array objectAtIndex:i];
    NSLog(@"temp length = %@", [temp length]);
}
Run Code Online (Sandbox Code Playgroud)

我在NSLog行遇到EXC_BAD_ACCESS错误.我认为它在[temp length]位错误.奇怪的是,我可以在temp上做其他NSString方法,它们工作得很好,就像[temp characterAtIndex:0].

我也尝试过[[array objectAtIndex:i] retain];,但这似乎没有帮助.

有谁知道我为什么会收到这个错误?


编辑:原来它在NSLog崩溃,因为它是%@而不是%lu.真正的问题是我从这篇文章中省略的其他代码.在玩了一些之后,我开始工作了.

cocoa objective-c nsstring

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