考虑parent带有子视图(child)的view ().两者都注册了拖动类型NSFilenamesPboardType.
parent只对图像文件和child音频文件感兴趣.如果他们检测到相应类型的文件,则draggingEntered:返回NSDragOperationCopy.如果没有,他们会回来NSDragOperationNone.
child重叠parent并且当拖动到达时child,无论是否对拖动感兴趣,parent都会收到draggingExited:消息child.
parent如果child不想要它怎么能接受拖动?
我只有在尝试构建iPhone静态库的单元测试时才会出现以下错误:
Undefined symbols for architecture i386:
"std::terminate()", referenced from:
-[ZipArchive dealloc] in libMyProject.a(ZipArchive.o)
"___gxx_personality_v0", referenced from:
Dwarf Exception Unwind Info (__eh_frame) in libMyProject.a(ZipArchive.o)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)
构建原始项目工作正常.
我能错过什么?
应该注意的是,ZipArchive是一个引用libz.dylib框架的.mm文件,该框架在原始项目和测试项目中都被引用.
此外,通常的Build Settings嫌疑人具有以下值:
框架搜索路径:"$(SDKROOT)/ Developer/Library/Frameworks""$(DEVELOPER_LIBRARY_DIR)/ Frameworks"
其他链接器标志:-all_load -lxml2 - ObjC
标题搜索路径:/ usr/include/libxml2
我正在使用Grand Central Dispatch来UITableViewCell异步加载图像.这种方法很有效,除了在一些边界情况下,单元格被重用,而前一个块加载了错误的图像.
我当前的代码如下所示:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
NSString *imagePath = [self imagePathForIndexPath:indexPath];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
dispatch_sync(dispatch_get_main_queue(), ^{
cell.imageView.image = image;
[cell setNeedsLayout];
});
});
return cell;
}
Run Code Online (Sandbox Code Playgroud)
据我所知,GCD队列无法停止.那么如何防止这种边界情况呢?或者我应该使用其他东西而不是GCD来解决这个问题?
Mountain Lion引入了新的API,其中一些我们已经在项目中作为类别实现.
对于例子,我们有一个类别NSColor+CGColorAdditions是实现CGColor和colorWithCGColor:为NSColor.Mountain Lion中添加了这些方法.
理想情况下,如果客户端操作系统比Mountain Lion更旧,我们希望使用这些类别,如果是Mountain Lion,则不使用它们.我们应该怎么做?还是有更好的选择吗?
我有一个基于文档的Cocoa应用程序,它使用辅助节点NSWindow进行预览模式(shouldCloseDocument设置为NO).
如果该文件是脏的(不保存修改),我关闭了二次NSWindow,一个"你想保存到文档所作的修改"提示出现.
如何在辅助设备上避免此提示NSWindow?
我的Cocoa基于文档的应用程序打开并编写自定义包/包.
这被认为是需要通过Exported UTI(UTExportedTypeDeclarations)导出的专有格式吗?
如果是这样,那么应该是什么值:
UTTypeConformsTo)public.mime-type)com.apple.nspboard-type)com.apple.ostype)最后,导出的UTI标识符(UTTypeIdentifier)是否需要与文档类型标识符(LSItemContentTypes)相同的值?
你如何有效地检查Cocoa中的两个文件是否相同(具有相同的数据)?
上下文:我正在编写一个程序,它接收一个文件作为输入(输入文件)并将其复制到一个目录中.如果目录已包含具有相同名称的文件(同名文件),则仅当同名文件不同时,才应使用新名称复制输入文件.
检查a NSNumber是否为分数的最佳方法是什么?
NumberIsFraction(@(0)); // NO;
NumberIsFraction(@(0.5)); // YES;
NumberIsFraction(@(1.0)); // NO;
Run Code Online (Sandbox Code Playgroud)
边境案件处理和绩效方面的"最佳".
如果我在方向更改期间更改UICollectionView的布局,我会EXC_BAD_ACCESS在几次旋转后得到.
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
UICollectionViewLayout *layout = [[UICollectionViewFlowLayout alloc] init];
self.myCollectionView.collectionViewLayout = layout; // This causes EXC_BAD_ACCESS after a few rotations
}
Run Code Online (Sandbox Code Playgroud)
这是一个UICollectionView错误吗?或者我做错了什么?如果这是一个错误,有没有办法在方向更改期间更改整个布局?
我注意到在这个答案中提到了同样的问题.使用NSZombies进行调试不会产生其他信息.
NSString在内存中考虑一组数千个对象.
搜索NSString集合中特定内容的最有效方法是什么?会用得NSDictionary够吗?或者它是否保证NSSet搜索是O(1)(找不到任何说明的文档)?
并且相同的策略是否适用于NSData对象?
macos ×6
ios ×4
objective-c ×4
cocoa ×3
iphone ×3
bundle ×1
categories ×1
file-io ×1
nscolor ×1
nsnumber ×1
nsstring ×1
nsview ×1
nswindow ×1
osx-lion ×1
search ×1
uitableview ×1
unit-testing ×1
uti ×1
xcode ×1
ziparchive ×1