小编Mic*_*ael的帖子

"wait_fences:未收到回复:10004003"?

由于以下代码行,我第一次(也是第一次)加载了我的视图时出现了这个神秘的错误:

- (void)viewWillAppear:(BOOL)animated
{
    [textField becomeFirstResponder];
}
Run Code Online (Sandbox Code Playgroud)

有一个明显的(约3 - 4秒,甚至在模拟器上)延迟,因为这使我的应用程序感到反应迟钝.有谁知道如何解决这一问题?我在Apple的网站上找不到任何文档,或者在Google或Google上找到任何解决方案.

奇怪的是,如果我把线放入-viewDidAppear:而不是-viewWillAppear:; 也就是说,不是打印错误仅在第一次键盘显示永不再,该错误打印第一次,但之后每次.这给我带来了很大的麻烦.

iphone cocoa-touch objective-c

94
推荐指数
8
解决办法
6万
查看次数

函数的多个参数由pthread_create()调用?

我需要将多个参数传递给我想在一个单独的线程上调用的函数.我已经读过,执行此操作的典型方法是定义结构,向函数传递指向该结构的指针,并为参数取消引用它.但是,我无法让它工作:

#include <stdio.h>
#include <pthread.h>

struct arg_struct {
    int arg1;
    int arg2;
};

void *print_the_arguments(void *arguments)
{
    struct arg_struct *args = (struct arg_struct *)args;
    printf("%d\n", args -> arg1);
    printf("%d\n", args -> arg2);
    pthread_exit(NULL);
    return NULL;
}

int main()
{
    pthread_t some_thread;
    struct arg_struct args;
    args.arg1 = 5;
    args.arg2 = 7;

    if (pthread_create(&some_thread, NULL, &print_the_arguments, (void *)&args) != 0) {
        printf("Uh-oh!\n");
        return -1;
    }

    return pthread_join(some_thread, NULL); /* Wait until thread is finished */
}
Run Code Online (Sandbox Code Playgroud)

这个输出应该是:

5
7
Run Code Online (Sandbox Code Playgroud)

但是当我运行它时,我实际得到: …

c pthreads

88
推荐指数
3
解决办法
15万
查看次数

如何使用iPhone SDK检查本地Wi-Fi(不仅仅是蜂窝连接)?

我目前正在使用以下内容检查我的应用程序是否可以使用Wi-Fi:

#import <SystemConfiguration/SystemConfiguration.h>
static inline BOOL addressReachable(const struct sockaddr_in *hostAddress);

BOOL localWiFiAvailable()
{
    struct sockaddr_in localWifiAddress;
    bzero(&localWifiAddress, sizeof(localWifiAddress));
    localWifiAddress.sin_len = sizeof(localWifiAddress);
    localWifiAddress.sin_family = AF_INET;
    // IN_LINKLOCALNETNUM is defined in <netinet/in.h> as 169.254.0.0
    localWifiAddress.sin_addr.s_addr = htonl(IN_LINKLOCALNETNUM);

    return addressReachable(&localWifiAddress);
}

static inline BOOL addressReachable(const struct sockaddr_in *hostAddress)
{
    const SCNetworkReachabilityRef target =
          SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault,
                                                 (const struct sockaddr *)hostAddress);
    if (target != NULL)
    {
        SCNetworkReachabilityFlags flags = 0;
        const BOOL reachable = SCNetworkReachabilityGetFlags(target, &flags);
        CFRelease(target);
        return reachable && (flags & kSCNetworkFlagsReachable);
    } …
Run Code Online (Sandbox Code Playgroud)

iphone cocoa-touch objective-c

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

为什么Objective-C使用YES和NO而不是1和0?

Objective-C使用YES和NO代替1和0是否有任何技术原因,或者仅仅是为了使其更具可读性?

objective-c

24
推荐指数
5
解决办法
2万
查看次数

如何在Python setup.py脚本中将标志传递给gcc?

我在C中编写了一个Python扩展,它需要CoreFoundation框架(以及其他内容).这编译好:

gcc -o foo foo.c -framework CoreFoundation -framework Python
Run Code Online (Sandbox Code Playgroud)

("-framework"是一个仅限Apple的gcc扩展,但这没关系因为我正在使用他们的特定框架)

如何告诉setup.py将此标志传递给gcc?

我试过这个,但它似乎不起作用(它编译,但当我尝试运行它时抱怨未定义的符号):

from distutils.core import setup, Extension
setup(name='foo',
      version='1.0',
      author='Me',
      ext_modules=[Extension('foo',
                             ['foo.c'],
                             extra_compile_args=['-framework CoreFoundation'])])
Run Code Online (Sandbox Code Playgroud)

编辑:

这似乎有效:

from distutils.core import setup, Extension
setup(name='foo',
      version='1.0',
      author='Me',
      ext_modules=[Extension('foo',
                             ['foo.c'],
                             extra_link_args=['-framework', 'CoreFoundation'])])
Run Code Online (Sandbox Code Playgroud)

python distutils python-c-api

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

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

检查是否用C预处理器声明了函数?

是否可以告诉C预处理器检查是否声明了函数(不是宏)?我尝试了以下方法,但它似乎不起作用:

#include <stdio.h>

int main(void)
{
#if defined(printf)
    printf("You support printf!\n");
#else
    puts("Either you don't support printf, or this test doesn't work.");
#endif
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c macros c-preprocessor

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

为Cocoa导入<Foundation/Foundation.h>时导入的文件?

只是好奇,什么文件都包括在内时,<Foundation/Foundation.h>或者<Cocoa/Cocoa.h>#import编?框架和/ usr/include中的所有文件?

cocoa objective-c

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

为什么Cocoa应用程序使用如此多的内存?

甚至在Xcode中创建新的Cocoa项目时构建的标准空白窗口Cocoa应用程序也使用了近6 MB的内存.这是什么原因?是否有可能使应用程序使用更少,或者OS X是否只是为Cocoa应用程序管理内存的方式不同?

不是我在抱怨.我知道性能"几乎不再重要"(编辑:我的意思是,它比可读性/可维护性/程序员的时间更重要).我只是好奇.

memory cocoa objective-c

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

将标题添加到模态视图控制器工具栏的正确方法?

现在我在我的-viewDidLoad方法中使用它:

UIToolbar *toolbar = [[UIToolbar alloc] init];

UIBarButtonItem *flexibleSpace = [UIBarButtonItem alloc];
flexibleSpace = [flexibleSpace initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
                                                    target:nil
                                                    action:nil];

// Add a back button to allow user to close the modal view
NSString *back = NSLocalizedString(@"Back", nil);
UIBarButtonItem *backButton = [UIBarButtonItem alloc];
backButton = [backButton initWithTitle:back
                                 style:UIBarButtonItemStyleDone
                                target:self
                                action:@selector(dismissModalViewControllerAnimated:)];

// Add a centered title to the toolbar

// I doubt this is the "correct" way to do this, but it seems to work.
// The "width" property of a …
Run Code Online (Sandbox Code Playgroud)

iphone cocoa-touch objective-c

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