小编Cod*_*aFi的帖子

文件名NSString在空间中添加了不必要的%20

已解决(感谢Regexident)

我有一个应用程序将PDF的文件路径传递给自定义-(id)initinit方法.它被添加到表中,当它被选中时,它会为不存在的文件调用else语句:

- (void) gridView:(AQGridView *)gridView didSelectItemAtIndex:(NSUInteger)index {

NSLog (@"Selected theArgument=%d\n", index);

UIViewController *viewController = [[[UIViewController alloc]init]autorelease];
{
    //if file is built-in, read from the bundle
    if (index <= 3)
    {
        // first section is our build-in documents
        NSString *fileURLs = [_documentIconsURLs objectAtIndex:index];   
        NSLog(@"file url -%@", fileURLs);
        viewController = [[[xSheetMusicViewController alloc]initWithContentURL:fileURLs]autorelease];
    }
    //if file is external, read from URL
    else
    {
        // second section is the contents of the Documents folder
        NSString *fileURL = [_documentIconsURLs objectAtIndex:index];
        NSLog(@"file url …
Run Code Online (Sandbox Code Playgroud)

file-sharing nsstring ipad ios

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

选择单身人士还是分类?

在我的应用程序的早期,当我的经验比我现在少得多时,我想用我自己的自定义动画为视图控制器之间的一些过渡增添趣味.我不知道从哪里开始,我环顾四周寻找像MVC这样的模式,可以随时从几乎任何控制器访问,事实证明,单身就是最佳选择.

我没有意识到的是,对单身人士模式似乎有一种强烈而善意的仇恨,而我自己也开始明白为什么,但这不是重点.

所以,不久之后,我决定将我的相同实现移动到UINavigationController上的一个类别(毕竟,它处理转换!),保留原始类以进行比较,并且想知道哪种方法最有效.在对这两种实现进行全面测试后,我可以毫无疑问地说它们在各个方面都是相同的,包括速度,准确度,平滑度,帧速率,内存使用等等,那么从总体可维护性的角度来看哪一个更"好"?

编辑:在阅读了你们所写的精心编写的论点后,我决定使用单例.@JustinXXVII已经提出了最有说服力的论点(恕我直言),虽然我认为这里的每个答案同样值得.谢谢大家的意见,我在问题中提出了所有答案.

singleton animation objective-c categories ios

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

Snappy压缩仅返回SNAPPY_INVALID_INPUT

我在NSData上写了一个用libSnappy进行压缩的简短类别.它在压缩过程中就像一个魅力,但解压缩代码会产生SNAPPY_INVALID_INPUT.有趣的是,尽管Op-Code无效,但snappy仍然result用未压缩的数据填充我的缓冲区.有谁知道为什么snappy向我扔这个?

- (NSData*)dataBySnappyUncompression {
    NSMutableData *result = nil;
    if (self.bytes != NULL) {
        size_t uncompress_result = 0;
        snappy_status opCode = snappy_uncompressed_length(self.bytes, self.length, &uncompress_result);
        if (opCode == SNAPPY_OK) {
            result = [NSMutableData dataWithLength:uncompress_result];
            opCode = snappy_uncompress(self.bytes, self.length, [result mutableBytes], &uncompress_result);
            if (opCode == SNAPPY_OK) {
                [result setLength:uncompress_result];
                return result;
            }
        }
    }
    LEPLog(@"Failed snappy de-compress: tried to de-compress %lu bytes", self.length);
    NSAssert(nil, @"Failed Snappy de-compress");
    result = nil;
    return result;
}
Run Code Online (Sandbox Code Playgroud)

我应该注意,正在压缩/未压缩的数据是NSKeyedArchiver调用的结果.

nsdata snappy

5
推荐指数
0
解决办法
636
查看次数

根据UITableView调整UIScrollView的高度

我有一个UIScrollView,其中包含一个UIView和一个UITableView。我的目标是调整UIScrollView的高度,以使我可以将UIScrollView的内容滚动到特定点。

这是我的观点:它的顶部是UIView,下面是UITableView。

在此处输入图片说明

滚动时,我希望UIView停在特定位置,如下所示: 在此处输入图片说明

tableView将能够继续滚动,但是UIView将被锁定在适当的位置,直到用户向上滚动并使UIView返回其原始状态为止。

我要尝试做的主要示例是iOS 6上的AppStore.app。当您查看应用程序的详细信息时,“详细信息”,“评论”和“相关”的过滤器栏将移至屏幕顶部并停止。我希望这一切都是有道理的。

谢谢

objective-c uitableview uiscrollview ios

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

多点触控基础(3个或更多手指)

我注意到iOS中缺少与真正的多点触控相关的问题.我不是在谈论一根手指的触摸事件,我在谈论三根或更多手指的触摸事件.是否有关于大量触摸输入的手势处理的任何来源或文档文章?如果没有,那么你们过去使用过的任何基本方法是否有效?

(PS我的最终目标是让NSLOG一个3指向下滑动).

objective-c multi-touch ipad ios

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

是什么 - [NSURL _fastCharacterContents] :?

所以我在一个方法中调用它:

-(id)initWithContentURL:(NSString *)url {
if (self = [super init]) {
    NSLog(@"xSheetMusicViewController - %@",url);
    // Casting an NSString object pointer to a CFStringRef:
    CFStringRef cfString = (CFStringRef)url;        
    CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), cfString, NULL, NULL);
    pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);
    }
    return self;
}
Run Code Online (Sandbox Code Playgroud)

哪一个在NSLog的标记处发生了崩溃:

CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), cfString, NULL, NULL);
Run Code Online (Sandbox Code Playgroud)

我从未见过这个奇妙的小错误.这是崩溃日志:

SheetMuse[83550:b603] -[NSURL _fastCharacterContents]: unrecognized selector sent to instance 0x4ec35f0
2011-09-22 17:36:22.921 SheetMuse[83550:b603] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURL _fastCharacterContents]: unrecognized selector sent to instance 0x4ec35f0'
*** Call …
Run Code Online (Sandbox Code Playgroud)

init nsstring cfstring ipad ios

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

1个部分的UITableview索引

我想知道是否可以提供帮助,即使您在表格视图中只有1个部分,也已经可以设置索引滚动。我有很多排序的表条目(超过50个),希望跳转到以下以A,B,C,D等开头的行-我对此很陌生,但是我已经关闭了,但是不能正常工作-你能帮我吗 ?

我的代码如下:

enter code here 
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {

NSMutableArray *tempArray = [[NSMutableArray alloc] init];
[tempArray addObject:@"A"];
[tempArray addObject:@"B"];
[tempArray addObject:@"C"];
[tempArray addObject:@"D"];
[tempArray addObject:@"F"];
[tempArray addObject:@"G"];
[tempArray addObject:@"H"];
[tempArray addObject:@"J"];
[tempArray addObject:@"K"];
[tempArray addObject:@"L"];
[tempArray addObject:@"M"];
[tempArray addObject:@"P"];
[tempArray addObject:@"S"];
[tempArray addObject:@"T"];
[tempArray addObject:@"U"];
[tempArray addObject:@"V"];    
return tempArray;
}

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString     *)title atIndex:(NSInteger)index {

if(index !=0){ 
    [tableView scrollToRowAtIndexPath:[NSIndexPath
    indexPathForRow:index inSection:0] 
    atScrollPosition:UITableViewScrollPositionTop animated:TRUE];
}
return index;
}
Run Code Online (Sandbox Code Playgroud)

objective-c uitableview ios

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

架构i386的重复符号,找不到类和文件的相同名称

当我使用Xcode 4.6编译我的iPhone应用程序时,我看到一个奇怪的错误代码:

"架构i386的重复符号".

我知道有关文件名或类名重复的问题.所以我尝试使用Finder中的搜索栏找到该文件.我还尝试使用Xcode中的搜索栏搜索重复的类,但是我找不到它.我已经检查过我没有导入.m文件.

接下来我该怎么办?请提出任何建议.

iphone xcode objective-c ios

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

保存,文档扩展和首选项(Info.plist)

我有一个简单的基于文档的Cocoa应用程序调用"RaiseMan".当我去保存文件时,控制台中会显示以下消息:

-[NSDocumentController fileExtensionsFromType:] is deprecated, and does not work when passed a uniform type identifier (UTI). If the application didn't invoke it directly then the problem is probably that some other NSDocument or NSDocumentController method is getting confused by a UTI that's not actually declared anywhere. Maybe it should be declared in the UTExportedTypeDeclarations section of this app's Info.plist but is not. The alleged UTI in question is "com.bignerdranch.raiseman-doc".

如果我将当前文件保存为"测试",则会显示一个以.plist打开的文件,并且不会使用Raiseman应用程序打开.如果我将其保存为"Test.rsmn"(明确键入扩展名),则将其保存为Raiseman类型文件,但是当我重新打开文件时,我无法访问任何用户首选项或首选项面板(.xib) .

背景:我目前正在通过Aaron Hillegass的Mac OS X编程,第13章......

xcode objective-c save plist xib

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

从有符号整数创建CGEvent

在我继续之前,我想在这篇文章的序言中说这可能是最讨厌,彻头彻尾的邪恶,令人讨厌的话题,所以我不希望任何答案都包含"合法"代码.

在尝试访问OS X Mountain Lion用于包含热键组合以激活听写的内部首选项文件时,我遇到了一些精美的有符号整数,其中包含System Preferences.app中定义的键代码.问题是,我能想到把它们变成a的唯一方法CGEvent是通过并基本解析出给定密钥代码的位掩码,这是一种潜在的无结果和烦人的努力.而且因为CGEvent方便地为内部struct(__CGEvent)定义了类型,所以没有办法看到它的内部组织(换句话说,我malloc()无法解决这个问题).到目前为止我所获得的是以下代码:

/***************************************UNSAFE*****************************************************/
//1048584, -1048585 - Two Left CMD presses; 1048576, -1048577 - Two CMD presses; 8388608, -8388609 - Two Fn presses; 1048592, -1048593 - Two Right CMD presses
- (void)forceDictation {

    NSString *path = [[NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) lastObject]stringByAppendingPathComponent:@"Preferences/com.apple.symbolichotkeys.plist"];
    NSDictionary *dictationPrefs = [NSDictionary dictionaryWithContentsOfFile:path];
    NSDictionary *dictationDict = dictationPrefs[@"AppleSymbolicHotKeys"];
    NSDictionary *keyvalueDict = dictationDict[@"164"];
    NSDictionary *valueDict = keyvalueDict[@"value"];
    NSArray *parameters = valueDict[@"parameters"];
    NSInteger firstCode = [[parameters objectAtIndex:0]longLongValue];
    NSInteger secondCode = …
Run Code Online (Sandbox Code Playgroud)

macos cocoa hotkeys objective-c bitmask

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