小编Mar*_*eau的帖子

在应用程序中使用unicode符号或形状是不好的做法吗?

曾经有几次我在我的一个Cocoa应用程序中使用unicode符号代替小图标,或者因为它更容易用文本内联绘制,或者因为我不想激发Photoshop来绘制一个简单的箭头.我想知道,我可能不知道本地化或字体是否存在问题?在这些符号可能与我在工作站上看到的符号不匹配的情况下是否存在?

unicode macos cocoa objective-c

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

在ObjectiveC和Cocoa中以编程方式创建彩色气泡/圆圈

任何人都可以用正确的方式指导我以编程方式构建彩色气泡/圆圈吗?

我不能使用图像,因为我需要它可以是任何颜色,取决于用户交互.

我的想法可能是制作一个白色圆圈图像,然后在它上面叠加一种颜色.但是我不确定这是否有用,或者如何真正实现它.

如果有人能指出我正确的方向,我会很感激.

cocoa drawing objective-c

14
推荐指数
4
解决办法
4万
查看次数

使用ARC在其自己的完成块中引用NSOperation对象

我将一些NSOperation代码转换为ARC时遇到了困难.我的操作对象使用完成块,该完成块又包含一个GCD块,用于更新主线程上的UI.因为我从自己的完成块中引用了我的操作对象,所以我使用__weak指针来避免内存泄漏.但是,在我的代码运行时,指针已经设置为nil.

我把它缩小到这个代码示例.谁知道我哪里出错了,以及正确的方法来实现这一目标?

NSOperationSubclass *operation = [[NSOperationSubclass alloc] init];
__weak NSOperationSubclass *weakOperation = operation;

[operation setCompletionBlock:^{
    dispatch_async( dispatch_get_main_queue(), ^{

        // fails the check
        NSAssert( weakOperation != nil, @"pointer is nil" );

        ...
    });
}];
Run Code Online (Sandbox Code Playgroud)

objective-c nsoperation grand-central-dispatch objective-c-blocks automatic-ref-counting

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

如果涉及绑定,如何覆盖NSError表示?

我在Cocoa Bindings中遇到的一件事就是错误呈现,例如当用户在附加了格式化程序的文本字段中键入错误的值时.通常我会覆盖willPresentError:响应器链中的某个地方,但我的问题是由Bindings系统创建的NSError对象不包含足够的信息让我告诉失败的内容,或者它是否是我对定制感兴趣的错误.我可以完全从等式中删除绑定并在验证问题发生时创建我自己的错误,但我觉得我会抛出一些有用的东西.

我已经能够通过实现NSControl委托方法并在视图控制器中存储实例变量中失败的控件来解决这个问题.如果时间willPresentError:到来之前它是非零的,我知道什么未能验证.

- (BOOL)control:(NSControl *)control didFailToFormatString:(NSString *)string errorDescription:(NSString *)error;
{
    _errorSender = [control retain];
    return NO;
}

- (NSError *)willPresentError:(NSError *)error;
{
    if ( _errorSender != nil )
    {
        NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:[error userInfo]];
        NSString *help = NSLocalizedString( @"Why are you always messing up? You are a terrible person.", @"" );

        [_errorSender release];
        _errorSender = nil;
        [userInfo setObject:help forKey:NSLocalizedRecoverySuggestionErrorKey];

        return [NSError errorWithDomain:[error domain] code:[error code] userInfo:userInfo];
    }

    return [super willPresentError:error];
}
Run Code Online (Sandbox Code Playgroud)

这在第一个响应者更改时有效,但在我调用commitEditing视图控制器时则不行,所以它对我来说只是部分有用. …

error-handling cocoa core-data objective-c cocoa-bindings

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

iPhone内存管理和发布

这是我经常看到的一种常见做法(包括来自非常受欢迎的iPhone开发者书籍)

在.h文件中:

@interface SomeViewController : UIViewController
{
  UIImageView *imgView;
}
Run Code Online (Sandbox Code Playgroud)

在.m文件中的某个地方:

imgView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen]
applicationFrame]];
[imgView setImage:[UIImage imageNamed:@"someimage.png"]];
[self addSubview:imgView];
[imgView release];
Run Code Online (Sandbox Code Playgroud)

后来,我们看到了......

- (void) dealloc
{
  [imgView release];
  [super dealloc];

} 
Run Code Online (Sandbox Code Playgroud)

由于imgView具有匹配的alloc和release,是否需要在dealloc中发布imgView?

addSubview调用保留的imgView在哪里占了?

iphone cocoa memory-management objective-c nsview

6
推荐指数
2
解决办法
3951
查看次数

一个窗口的背景图象在可可粉框架

我正在寻找一个完美的解决方案来为可可应用程序中的窗口设置背景图像.我还没有找到解决方案,我是目标c的新手,所以请任何人帮助我......

cocoa objective-c

6
推荐指数
2
解决办法
7535
查看次数

Cocoa一行表视图或水平列表视图

是否可以使用表视图来显示大量元素的一行?我正在寻找的是某种水平列表,就像我们在XCode首选项或Aperture图像列表中一样.

它的行为就像一个columnt表视图,但不是垂直显示元素,而是应该是水平的.

你能指出我应该从哪里开始吗?

cocoa objective-c

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

在Cocoa中向窗口添加自定义视图

我正在为Mac OSX创建一个示例应用程序.我创建了一个包含登录按钮的窗口,我添加了一个新的自定义视图.现在,当用户单击登录按钮时,我需要将自定义视图加载到窗口.请有人帮帮我......

cocoa objective-c

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

NSThreads的问题

我的应用程序崩溃了 [NSThread detachNewThreadSelector: @selector(getJSON:) toTarget:self withObject:nil];

以下是getJSON函数的外观: - (void)getJSON: (NSDate *)startTime endTime:(NSDate *)endTime;

这有什么问题?

multithreading objective-c

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

在cocoa中查找已安装的应用程序

我正在开发一个可可的应用程序.我需要检查iTunes是否安装在机器中.是否有任何方法可以找到已安装的应用程序????

macos cocoa

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

尝试使用CGRect时出现语法错误

我正在尝试将子视图添加到tableview单元格中,当然也使用CGRect作为其中的一部分.但是,我在构建时遇到语法错误:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    switch (indexPath.section) {
        case 1:
            CGRect <<- SYNTAX ERROR cellFrame = CGRectMake(0, 0, 300, 65);
            cell = [[[UITableViewCell alloc] initWithFrame:cellFrame reuseIdentifier: CellIdentifier] autorelease];

            CGRect infoRect = CGRectMake(0, 5, 295, 55);
            UILabel *infoLabel = [[UILabel alloc] initWithFrame:infoRect];
            infoLabel.tag = 1;
            [cell.contentView addSubview:infoLabel];
            [infoLabel release];
            break;
        default:
            break;
    }
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
Run Code Online (Sandbox Code Playgroud)

我试过右键单击框架 - …

iphone objective-c

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