NSFetchedResultsController:删除1行崩溃的应用程序

从NSFetchedResultsController提供的UITableView中删除一行会导致我的应用程序崩溃。 错误是: *断言失败 – [UITableView _endCellAnimationsWithContext:],/ SourceCache /UIKit/UIKit-2903.23/UITableView.m:1330 *终止应用程序,由于未捕获exception“NSInternalInconsistencyException”,原因:“无效的更新:在0节中的行数无效。更新(1)后,现有节中包含的行数必须等于包含在更新之前的那个部分(1),加上或者减去从该部分插入或者删除的行数(0插入,1个删除)以及加或者减去移入或移出该部分的行数(移入0,0搬出)。' 我只想轻扫即可删除。 我的删除代码是这样的: – (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { [self.tableView beginUpdates]; SequenceData *sd = [self.fetchedResultsController objectAtIndexPath:indexPath]; [self.managedObjectContext deleteObject:sd]; [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; [self.tableView endUpdates]; } 我的NSFetchedResultsController的设置就像在Ray Wanderlich的教程中一样( http://www.raywenderlich.com/999/core-data-tutorial-for-ios-how-to-use-nsfetchedresultscontroller ) 行数取决于: – (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { id sectionObjects = [[self.fetchedResultsController sections] objectAtIndex:section]; NSInteger nbObjects = [sectionObjects numberOfObjects]; […]

如何使用ALAssetsLibrary将图像path转换为uiimage

我的iPhone应用程序有一个数组用于存储用户窗体库select的图像path。 我想使用ALAssetsLibrary将数组中的所有图像path转换为uiimage。 我该如何做这个动作? 我尝试使用循环,但不能。 Thx的帮助。 ALAssetsLibrary *library = [[[ALAssetsLibrary alloc] init] autorelease]; [library assetForURL:[filePath objectAtIndex:0] resultBlock:^(ALAsset *asset) { UIImage *image = [UIImage imageWithCGImage:[[asset defaultRepresentation] fullResolutionImage]]; [fileImage addObject:image]; } failureBlock:^(NSError *error) { }];

如何在每增加50点后加速一个Sprite Kit游戏

我正在用Sprite Kit制作一个2D游戏,我需要添加一个方法来在每50分钟后加速游戏。 我制定了一个方法来增加速度,但是我必须复制,粘贴和调整更新方法中的if语句每增加50点。 我的解决scheme的另一个问题是,我必须在加速之后立刻给我的分数加分,因为如果不是这样,游戏速度就会完全加快,但我不知道为什么。 到目前为止,我的解决scheme是: // inside the update method // points are added when an enemy is destroyed // pointSpeed is the float variable that is used to change positions if (points == 4) { pointSpeed++; points++; } if (points == 8) { pointSpeed++; points++; } if (points == 12) { pointSpeed++; points++; } […]

Xcode AVCapturesession扫描特定帧中的条形码(rectOfInterest不起作用)

我正试图为我目前正在使用的应用程序devise一款条形码扫描器。 我希望扫描仪预览填充设备的整个屏幕,并提供一个更小的框架指向条形码。 所有的工作是如何我想要的,但我不能得到的利益框架的工作。 这里是条码扫描器的实现: #import "GEScannerViewController.h" @import AVFoundation; @interface GEScannerViewController () <AVCaptureMetadataOutputObjectsDelegate> { AVCaptureSession *_session; AVCaptureDevice *_device; AVCaptureDeviceInput *_input; AVCaptureMetadataOutput *_output; AVCaptureVideoPreviewLayer *_prevLayer; UIView *_greyView; UIView *_highlightView; UIView *_scopeView; UILabel *_label; } @end @implementation GEScannerViewController – (void)viewDidLoad { [super viewDidLoad]; _label = [[UILabel alloc] init]; _label.frame = CGRectMake(0, self.view.bounds.size.height – 40, self.view.bounds.size.width, 40); _label.autoresizingMask = […]

用CoreGraphics绘制半圆

我知道如何用CGPath绘制线条和形状。 但我不知道如何绘制这个符号的电路图 我应该写什么代码来获得半圆形状? 这是我迄今为止: – (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(context, 5.0); CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor); CGContextMoveToPoint(context, 60, 80); CGContextAddLineToPoint(context, 120, 80); CGContextMoveToPoint(context, 120, 80); CGContextAddArc(120,80,M_PI,M_PI/2); CGContextMoveToPoint(context, 200, 80); CGContextAddLineToPoint(context, 300, 80); CGContextStrokePath(context); }

iOS计时器在后台

我想在我的iOS应用程序启动一个计时器,当应用程序在后台运行,当应用程序closures。 定时器必须每隔30分钟检查一次新的通知。 在计时器function中,他们每30分钟调用另一个函数showNotification()。 我该如何做这个计时器,以及在应用程序未在后台运行/运行时,我必须在哪个位置调用计时器。

用户在运动中的距离

我正在编写一个应用程序,在用户走动时显示用户与固定点的距离(即每次用户移动时,显示用户到点的距离的标签都会更新)。 我使用了一个CLLocationManager,代码如下: – (void)viewDidLoad { locationManager=[[CLLocationManager alloc]init]; locationManager.distanceFilter = kCLDistanceFilterNone; locationManager.desiredAccuracy = kCLLocationAccuracyBest; [locationManager startUpdatingLocation]; } -(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { CLLocationDistance meters = [newLocation distanceFromLocation:fixedPoint]; self.distanceLabel.text = [[NSString alloc] initWithFormat:@"Distance: %.1f feet", meters*3.2808399]; } 应该显示从用户到点的距离的标签不会不断更新,更新时通常不会显示从用户到固定点的正确距离。 我想知道是否有更好的方法来尝试这样做,或者做核心位置框架的根本局限性,这是不可能的。 任何帮助将不胜感激。

如何获得主包中子文件夹的path?

我有一个项目,我正在从Obj-C迁移到Swift 3.0(而且我在Swift中是个不错的select)。 我如何翻译这一行? NSString *folder = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"myfolder"]; 我设法得到资源path: let resoursePath = Bundle.main.resoursePath; 但是,如何获得名为“myfolder”的子文件夹? 我需要得到一个path的子文件夹,而不是path里面的文件。

在后台线程中加载UIImage

是否有可能在后台线程中加载UIImage而不会导致线程问题? 如果不是这样做的最好方法是什么? 我正在使用iOS 8.这是我现在这样做的方式: dispatch_queue_t backgroundQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0); dispatch_async(backgroundQueue, ^{ UIImage *image = [UIImage imageNamed: fileName]; // only update UI on the main thread dispatch_async(dispatch_get_main_queue(), ^{ [self setImage: image]; }); });

如何将Objective-C静态库绑定到Xamarin.iOS?

我已经阅读了Xamarin的文档。 这是Objective-C中的testing类: #import "XamarinBundleLib.h" @implementation XamarinBundleLib +(NSString *)testBinding{ return @"Hello Binding"; } @end 这很简单,只是一种方法。 这是我的C#类: namespace ResloveName { [BaseType (typeof (NSObject))] public partial interface IXamarinBundleLib { [Static,Export ("testBinding")] NSString TestBinding {get;} } } 那么这是我的AppDelegate代码: public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions) { // Override point for customization after application launch. // If not required […]