错误一:
编译会报错:ARC forbids Objective-C object in struct ARC模式下,不允许将OC对象定义在结构体中
修正: 定义语句前加 __unsafe_unretained
错误二:
修正:语句前加 __block
错误三:
运行警告:在后台非主线程中刷新UI:
This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes
修正:方法一:通过GCD,在主线程执行代码
dispatch_async(dispatch_get_main_queue(), ^{
。。。
});
方法二:通过通知,但是通知的注册应该在主线程,如下需要用到queue参数,并且传mainQueue参数。
addObserverForName:@"notification"
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification *note){
// Do UI stuff here
}
方法三:在主线程发起通知
[self performSelectorOnMainThread:@selector(postNotification:) withObject:notification waitUntilDone:NO];
错误四:
在ipad上实现AlertController时,运行报错:
Terminating app due to uncaught exception 'NSGenericException', reason: 'Your application has presented a UIAlertController (<UIAlertController: 0x181b6400>) of style UIAlertControllerStyleActionSheet. The modalPresentationStyle of a UIAlertController with this style is UIModalPresentationPopover. You must provide location information for this popover through the alert controller's popoverPresentationController. You must provide either a sourceView and sourceRect or a barButtonItem. If this information is not known when you present the alert controller, you may provide it in the UIPopoverPresentationControllerDelegate method -prepareForPopoverPresentation.'
解决方案,来自stackoverflow:
You can present a
UIAlertController
from a popover by usingUIPopoverPresentationController
.起关键作用的代码用红色标记。UIViewController *self; // code assumes you're in a view controller UIButton *button; // the button you want to show the popup sheet from UIAlertController *alertController; UIAlertAction *destroyAction; UIAlertAction *otherAction; alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet]; destroyAction = [UIAlertAction actionWithTitle:@"Remove All Data" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { // do destructive stuff here }]; otherAction = [UIAlertAction actionWithTitle:@"Blah" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { // do something here }]; // note: you can control the order buttons are shown, unlike UIActionSheet [alertController addAction:destroyAction]; [alertController addAction:otherAction]; [alertController setModalPresentationStyle:UIModalPresentationPopover]; UIPopoverPresentationController *popPresenter = [alertController popoverPresentationController]; popPresenter.sourceView = button; popPresenter.sourceRect = button.bounds; [self presentViewController:alertController animated:YES completion:nil];
错误五:
在通过[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];删除cell时,总是崩溃:
网友大多建议尝试
[tableView beginUpdates];
[tableView endUpdates];
[tableView reloadData];
或者重新创建indexPath等等。但是都不适合我这里的情况,折磨我够长的时间,最后在stackoverflow上偶尔看到,
可能是你没有删除对应model中的数据,果然,我在添加对模型数据的删除后,成功执行了。
问题:在开发中,引入了zip库,出现下面的错误
Undefined symbols for architecture i386: "_compressBound", referenced from: +[NSDataGZipAdditions compressedDataWithBytes:length:] in NSDataGZipAdditions.o "_compress", referenced from: +[NSDataGZipAdditions compressedDataWithBytes:length:] in NSDataGZipAdditions.o "_inflateInit_", referenced from: +[NSDataGZipAdditions dataWithCompressedBytes:length:] in NSDataGZipAdditions.o "_inflate", referenced from: +[NSDataGZipAdditions dataWithCompressedBytes:length:] in NSDataGZipAdditions.o -[ParserForMainReturn uncompressZippedData:] in ParserForMainReturn.o "_inflateEnd", referenced from: +[NSDataGZipAdditions dataWithCompressedBytes:length:] in NSDataGZipAdditions.o -[ParserForMainReturn uncompressZippedData:] in ParserForMainReturn.o "_inflateInit2_", referenced from: -[ParserForMainReturn uncompressZippedData:] in ParserForMainReturn.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation)如果老是出现上面的错误。那么在工程中加入libz.dlib 文件