小编Oli*_*ver的帖子

iPhone - NSError参考:常量和代码

我正在搜索一些精确的文档,我可以将错误号与其常量相关联.比如说,我正在搜索NSError.code = 102的常量.我该怎么做才能找到它?搜索网络没有帮助.搜索头文件很麻烦.

你会怎么做?

iphone constants nserror

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

Cocoa - 定义像NSLog这样的全局函数

看到该帖子和接受的答案:

在XCode中,有没有办法在调用NSLog时禁用调试器控制台中出现的时间戳?

对于那个例子或任何其他情况,我怎么可以声明一个包含objective-c调用的全局函数,我可以直接调用它,比如NSLog,而不必像[MyClass myFunction]那样进行调用?

cocoa function ios

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

PHP - preg_match和"未知修饰符"错误

我有那个测试工作正常:

if (ereg("([0-9]{2})[-./]([0-9]{2})[-./]([0-9]{4})[ ]([0-9]{2}):([0-9]{2}):([0-9]{2})", $dateToTest, $tab) == false)
Run Code Online (Sandbox Code Playgroud)

并且随着ereg的弃用,我用这个替换了测试:

if (preg_match("/([0-9]{2})[-./]([0-9]{2})[-./]([0-9]{4})[ ]([0-9]{2}):([0-9]{2}):([0-9]{2})/", $dateToTest, $tab) == false)
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误:

Warning: preg_match() [function.preg-match]: Unknown modifier '.' in ..................
Run Code Online (Sandbox Code Playgroud)

有什么问题,我该如何解决?

php regex preg-match ereg

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

Objective-C - 优化这种单例模式?

我在网上发现了单身人士模式.在我看来,它有许多可以优化的东西.

- 在sharedMySingleton方法中,不需要调用保留?我不确定...... -
如果不是,为什么还有保留allocWithZone
- 是什么用的@synchronized.NSAssert认为可以多次调用块,所以如果是的话,应该有更多的代码来释放先前的内存,或者在没有NSAsserting的情况下清楚地退出块,如果没有,为什么会出现这个NSAssert?
- 链子beetween sharedMySingletonalloc似乎很奇怪.我自己写了类似的东西:

+(MySingleton*)sharedMySingleton
{
    @synchronized([MySingleton class])
    {
        if (_sharedMySingleton == nil) _sharedMySingleton = [[self alloc] init];
        return _sharedMySingleton;
    }

    return nil;
}

+(id)alloc
{
    @synchronized([MySingleton class])
    {
        return [super alloc];
    }

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

单身模式

#import "MySingleton.h"

@implementation MySingleton

// ##########################################################################################################
// ######################################## SINGLETON PART ##################################################
// ##########################################################################################################
static MySingleton* _sharedMySingleton = nil;

// =================================================================================================
+(MySingleton*)sharedMySingleton
// =================================================================================================
{
    @synchronized([MySingleton class])
    {
        if …
Run Code Online (Sandbox Code Playgroud)

iphone singleton memory-management objective-c ios

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

Objective-C:向类别添加属性

我已经为NSDate构建了一个类别,我想在这个类别中封装一个属性来保存一些数据.但我无法实现添加此属性,只能添加方法.

有没有办法实现这个目标?

谢谢.

attributes objective-c categories

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

iPhone - 自动检索XCode 4中丢失的文件

将文件和文件夹结构更改为finder时,是否有办法让XCode在项目文件夹中找到丢失的文件,而不必再导入整个内容并在导入过程后重新组织项目结构?

iphone import xcode file

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

Cocoa - 连接:didFailWithError错误代码

我在哪里可以找到错误代码及其连接的含义:didFailWithError方法可以给出?

iphone error-handling cocoa

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

Cocoa - 来自无处的NSError描述

我有这段代码:

- (void)connection:(NSURLConnection*)connection didReceiveResponse:(NSURLResponse*)response 
{
    if ([response respondsToSelector:@selector(statusCode)]) {

        int statusCode = [((NSHTTPURLResponse*)response) statusCode];
        if (statusCode >= 400) {
            NSError* statusError = [NSError errorWithDomain:@"Server connection error" code:statusCode userInfo:nil];
            [self connection:connection didFailWithError:statusError];
        }
    }
}

- (void)connection:(NSURLConnection*)connection didFailWithError:(NSError*)error 
{
NSLog(@"%@", [error localizedDescription]);
}
Run Code Online (Sandbox Code Playgroud)

这给了一个缺页:

- >操作无法完成.(服务器连接错误错误404.)

描述(本地化与否)来自何处?
我刚刚使用代码和自定义无意义域字符串初始化了NSError ...

iphone cocoa nserror

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

iPhone - NSDate格式:时间和时区的奇怪值

我测试了那些电话:

    NSLog(@"%@", [NSDate date]);
    NSLog(@"%@", [NSDate convertToUTC:[NSDate date]]);
    NSLog(@"%@", [[NSDate date] stringValueWithFormat:@"yyyyMMddHHmmss"]);
    NSLog(@"%@", [[NSDate convertToUTC:[NSDate date]] stringValueWithFormat:@"yyyyMMddHHmmss"]);

+ (NSDate*) convertToUTC:(NSDate*)sourceDate {
    [NSTimeZone resetSystemTimeZone];
    NSTimeZone* currentTimeZone = [NSTimeZone localTimeZone];
    NSTimeZone* utcTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"UTC"];

    NSInteger currentGMTOffset = [currentTimeZone secondsFromGMTForDate:sourceDate];
    NSInteger gmtOffset = [utcTimeZone secondsFromGMTForDate:sourceDate];
    NSTimeInterval gmtInterval = gmtOffset - currentGMTOffset;

    NSDate* destinationDate = [[[NSDate alloc] initWithTimeInterval:gmtInterval sinceDate:sourceDate] autorelease];     
    return destinationDate;
}
- (NSString*) stringValueWithFormat:(NSString*)formatRetour {
    NSDateFormatter* dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
    [dateFormatter setDateFormat:formatRetour];

    return [dateFormatter stringFromDate:self];
}
Run Code Online (Sandbox Code Playgroud)

他们给我:

2011-08-17 13:03:58 …
Run Code Online (Sandbox Code Playgroud)

iphone time cocoa datetime ios

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

NSInvalidArgumentException"无法识别的选择器发送到实例"(使用MPMoviePlayerController)

好吧,我在RootViewController中有一个带有DetailViewController的TableView,用于显示单个记录的信息.在详细信息页面中,我必须播放多媒体文件,并且我正在使用框架MediaPlayer,根据本指南:http: //www.techotopia.com/index.php/Video_Playback_from_within_an_iOS_4_iPhone_Application

看起来一切都好,但是当我点击播放按钮时我有这个错误:

 -[DetailsViewController playmovie]: unrecognized selector sent to instance 0x9117f60

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DetailsViewController playmovie]: unrecognized selector sent to instance 0x9117f60'
Run Code Online (Sandbox Code Playgroud)

这些是我的文件:

在AppDelegate中我使用这个导航控制器:

[...]

// Create a table view controller
    RootViewController *rootViewController = [[RootViewController alloc]
                                              initWithStyle:UITableViewStylePlain];

    rootViewController.managedObjectContext = context;
    rootViewController.entityName = @"Porti";


    UINavigationController *aNavigationController = [[UINavigationController alloc]
                                                     initWithRootViewController:rootViewController];

    self.navigationController = aNavigationController;


    UIBarButtonItem *homeButton;
    homeButton = [[[UIBarButtonItem alloc] initWithTitle:@"              Inizio              " style:UIBarButtonItemStyleBordered target:self action:@selector(home)] autorelease];

    UIBarButtonItem *barButton;
    barButton = [[[UIBarButtonItem alloc] …
Run Code Online (Sandbox Code Playgroud)

mpmovieplayercontroller navigationcontroller ios unrecognized-selector

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