我正在搜索一些精确的文档,我可以将错误号与其常量相关联.比如说,我正在搜索NSError.code = 102的常量.我该怎么做才能找到它?搜索网络没有帮助.搜索头文件很麻烦.
你会怎么做?
看到该帖子和接受的答案:
在XCode中,有没有办法在调用NSLog时禁用调试器控制台中出现的时间戳?
对于那个例子或任何其他情况,我怎么可以声明一个包含objective-c调用的全局函数,我可以直接调用它,比如NSLog,而不必像[MyClass myFunction]那样进行调用?
我有那个测试工作正常:
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)
有什么问题,我该如何解决?
我在网上发现了单身人士模式.在我看来,它有许多可以优化的东西.
- 在sharedMySingleton方法中,不需要调用保留?我不确定...... -
如果不是,为什么还有保留allocWithZone?
- 是什么用的@synchronized.NSAssert认为可以多次调用块,所以如果是的话,应该有更多的代码来释放先前的内存,或者在没有NSAsserting的情况下清楚地退出块,如果没有,为什么会出现这个NSAssert?
- 链子beetween sharedMySingleton和alloc似乎很奇怪.我自己写了类似的东西:
+(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) 我已经为NSDate构建了一个类别,我想在这个类别中封装一个属性来保存一些数据.但我无法实现添加此属性,只能添加方法.
有没有办法实现这个目标?
谢谢.
将文件和文件夹结构更改为finder时,是否有办法让XCode在项目文件夹中找到丢失的文件,而不必再导入整个内容并在导入过程后重新组织项目结构?
我在哪里可以找到错误代码及其连接的含义:didFailWithError方法可以给出?
我有这段代码:
- (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 ...
我测试了那些电话:
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) 好吧,我在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
iphone ×6
cocoa ×4
ios ×4
nserror ×2
objective-c ×2
attributes ×1
categories ×1
constants ×1
datetime ×1
ereg ×1
file ×1
function ×1
import ×1
php ×1
preg-match ×1
regex ×1
singleton ×1
time ×1
xcode ×1