更新3这些是第一次运行空数据存储后的日志.
2013-02-07 20:57:06.708 Five Hundred Things[14763:c07] mainMOC = <NSManagedobjectContext: 0x7475a90>
2013-02-07 20:57:06.711 Five Hundred Things[14763:1303] Import started
2013-02-07 20:57:06.712 Five Hundred Things[14763:1303] backgroundMOC = <NSManagedobjectContext: 0x8570070>
2013-02-07 20:57:06.717 Five Hundred Things[14763:c07] FRC fetch performed
2013-02-07 20:57:06.718 Five Hundred Things[14763:c07] numberOfSectionsInTableView returns 1
2013-02-07 20:57:06.720 Five Hundred Things[14763:c07] numberOfSectionsInTableView returns 1
2013-02-07 20:57:06.720 Five Hundred Things[14763:c07] numberOfRowsInSection returns 0
2013-02-07 20:57:06.728 Five Hundred Things[14763:1303] call contextDidSave
2013-02-07 20:57:06.736 Five Hundred Things[14763:1303] call contextDidSave
2013-02-07 20:57:06.736 Five Hundred Things[14763:c07] numberOfSectionsInTableView returns 1
2013-02-07 20:57:06.737 Five Hundred Things[14763:c07] numberOfSectionsInTableView returns 1
2013-02-07 20:57:06.737 Five Hundred Things[14763:c07] numberOfRowsInSection returns 5
2013-02-07 20:57:06.758 Five Hundred Things[14763:1303] call contextDidSave
2013-02-07 20:57:06.759 Five Hundred Things[14763:1303] Refresh complete
2013-02-07 20:57:06.759 Five Hundred Things[14763:c07] numberOfSectionsInTableView returns 1
2013-02-07 20:57:06.760 Five Hundred Things[14763:c07] numberOfSectionsInTableView returns 1
2013-02-07 20:57:06.761 Five Hundred Things[14763:c07] numberOfRowsInSection returns 5

请注意,执行FRC提取,节中的行数为0,但在第二个contextDidSave之后,它将更改为5以匹配数据存储中的类别数.

在崩溃的第二次运行中,这是日志:

2013-02-07 21:01:11.578 Five Hundred Things[14800:c07] mainMOC = <NSManagedobjectContext: 0x8225650>
2013-02-07 21:01:11.581 Five Hundred Things[14800:1303] Import started
2013-02-07 21:01:11.582 Five Hundred Things[14800:1303] backgroundMOC = <NSManagedobjectContext: 0x7439850>
2013-02-07 21:01:11.592 Five Hundred Things[14800:c07] FRC fetch performed
2013-02-07 21:01:11.594 Five Hundred Things[14800:c07] cat = Attraction
2013-02-07 21:01:11.594 Five Hundred Things[14800:c07] cat = Beverage
2013-02-07 21:01:11.595 Five Hundred Things[14800:c07] cat = Entertainment
2013-02-07 21:01:11.595 Five Hundred Things[14800:c07] cat = Hotel
2013-02-07 21:01:11.596 Five Hundred Things[14800:c07] cat = Restaurant
2013-02-07 21:01:11.597 Five Hundred Things[14800:c07] numberOfSectionsInTableView returns 1
2013-02-07 21:01:11.598 Five Hundred Things[14800:c07] numberOfSectionsInTableView returns 1
2013-02-07 21:01:11.599 Five Hundred Things[14800:c07] numberOfRowsInSection returns 0
2013-02-07 21:01:11.602 Five Hundred Things[14800:1303] call contextDidSave
2013-02-07 21:01:11.610 Five Hundred Things[14800:1303] call contextDidSave

初始化FRC,然后立即记录类别以显示它们确实在FRC中.但是,该部分中的行数为0,并且永远不会更新.相反,应用程序崩溃与下面的堆栈.

在第三次和后续运行中,这就是日志的样子:

2013-02-07 21:03:55.560 Five Hundred Things[14815:c07] mainMOC = <NSManagedobjectContext: 0x8128860>
2013-02-07 21:03:55.563 Five Hundred Things[14815:1e03] Import started
2013-02-07 21:03:55.564 Five Hundred Things[14815:1e03] backgroundMOC = <NSManagedobjectContext: 0x822b5d0>
2013-02-07 21:03:55.569 Five Hundred Things[14815:c07] FRC fetch performed
2013-02-07 21:03:55.571 Five Hundred Things[14815:c07] cat = Attraction
2013-02-07 21:03:55.572 Five Hundred Things[14815:c07] cat = Beverage
2013-02-07 21:03:55.572 Five Hundred Things[14815:c07] cat = Entertainment
2013-02-07 21:03:55.573 Five Hundred Things[14815:c07] cat = Hotel
2013-02-07 21:03:55.573 Five Hundred Things[14815:c07] cat = Restaurant
2013-02-07 21:03:55.574 Five Hundred Things[14815:c07] numberOfSectionsInTableView returns 1
2013-02-07 21:03:55.576 Five Hundred Things[14815:c07] numberOfSectionsInTableView returns 1
2013-02-07 21:03:55.576 Five Hundred Things[14815:c07] numberOfRowsInSection returns 5
2013-02-07 21:03:55.581 Five Hundred Things[14815:1e03] call contextDidSave
2013-02-07 21:03:55.592 Five Hundred Things[14815:1e03] call contextDidSave
2013-02-07 21:03:55.593 Five Hundred Things[14815:c07] numberOfSectionsInTableView returns 1
2013-02-07 21:03:55.594 Five Hundred Things[14815:c07] numberOfSectionsInTableView returns 1
2013-02-07 21:03:55.595 Five Hundred Things[14815:c07] numberOfRowsInSection returns 5
2013-02-07 21:03:55.606 Five Hundred Things[14815:1e03] call contextDidSave
2013-02-07 21:03:55.606 Five Hundred Things[14815:1e03] Refresh complete

这是第二次运行时的行为;数据已经存储在商店中,该部分中的行数返回5,并且类别会立即显示在表视图中.

更新2这是主线程的堆栈跟踪,它是崩溃发生的地方.因为它发生在主线程上,我认为它与UITableView有关.我不是在UITableView中使用NSDictionary或NSMutableDictionary.我现在的想法是numberOfRowsInSection在第二次运行时返回0导致问题,但我不知道如何解决它.它在第三次运行时返回正确的数字(我正在使用的数据为5),并且似乎在第一次运行时正确填充数据存储,所以我很困惑为什么在第二次运行时它返回0并且没有不要更新.

frame #0: 0x013ede52 libobjc.A.dylib`objc_exception_throw
frame #1: 0x020330de CoreFoundation`-[__NSDictionaryM setobject:forKey:] + 158
frame #2: 0x01211d7a CoreData`-[NSFetchedResultsController(PrivateMethods) _preprocessUpdatedobjects:insertsInfo:deletesInfo:updatesInfo:sectionsWithDeletes:newSectionNames:treatAsRefreshes:] + 1994
frame #3: 0x01212ed7 CoreData`-[NSFetchedResultsController(PrivateMethods) _managedobjectContextDidChange:] + 2455
frame #4: 0x00b9e4f9 Foundation`__57-[NSNotificationCenter addobserver:selector:name:object:]_block_invoke_0 + 40
frame #5: 0x0200a0c5 CoreFoundation`___CFXNotificationPost_block_invoke_0 + 85
frame #6: 0x01f64efa CoreFoundation`_CFXNotificationPost + 2122
frame #7: 0x00ad2bb2 Foundation`-[NSNotificationCenter postNotificationName:object:userInfo:] + 98
frame #8: 0x01125163 CoreData`-[NSManagedobjectContext(_NSInternalNotificationHandling) _postObjectsDidChangeNotificationWithUserInfo:] + 83
frame #9: 0x011bed2f CoreData`-[NSManagedobjectContext(_NSInternalChangeProcessing) _createAndPostChangeNotification:withDeletions:withUpdates:withRefreshes:] + 367
frame #10: 0x01121128 CoreData`-[NSManagedobjectContext(_NSInternalChangeProcessing) _postRefreshedobjectsNotificationAndClearList] + 136
frame #11: 0x0111f8c0 CoreData`-[NSManagedobjectContext(_NSInternalChangeProcessing) _processRecentChanges:] + 80
frame #12: 0x0111f869 CoreData`-[NSManagedobjectContext processpendingChanges] + 41
frame #13: 0x010f3e38 CoreData`_performRunLoopAction + 280
frame #14: 0x01f78afe CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
frame #15: 0x01f78a3d CoreFoundation`__CFRunLoopDoObservers + 381
frame #16: 0x01f567c2 CoreFoundation`__CFRunLoopRun + 1106
frame #17: 0x01f55f44 CoreFoundation`CFRunLoopRunSpecific + 276
frame #18: 0x01f55e1b CoreFoundation`CFRunLoopRunInMode + 123
frame #19: 0x01f0a7e3 GraphicsServices`GSEventRunModal + 88
frame #20: 0x01f0a668 GraphicsServices`GSEventRun + 104
frame #21: 0x00021ffc UIKit`UIApplicationMain + 1211
frame #22: 0x000022dd Five Hundred Things`main(argc=1,argv=0xbffff31c) + 141 at main.m:16
frame #23: 0x00002205 Five Hundred Things`start + 53

更新:我设法得到一个真正的崩溃而不是没有回应.

* Terminating app due to uncaught exception ‘NSinvalidargumentexception’,reason: ‘* setobjectForKey: object cannot be nil (key: _ContentChange_OldindexPathKey)’

This SO question是我能找到的最接近错误的,但它讨论的值是nil而不是key.当类别被保存到Core Data存储时,它看起来会发生,但所有类别都有值.

实体类别包含
category_id – 整数16
category_name – 字符串

它与实体Thing有很多关系,但代码的这个特定部分对这种关系没有做任何事情;它只设置category_id和category_name.稍后在导入(在MOC保存之后)是关系设置的时间.

导入操作中的代码:

//import categories

    Nsstring *categoryPath = [[NSBundle mainBundle] pathForResource:@"category" ofType:@"json"];

    NSData *categoryData = [NSData dataWithContentsOfFile:categoryPath];

    NSDictionary *categoryResults = [NSJSONSerialization
                                     JSONObjectWithData:categoryData
                                     options:NSJSONReadingMutableLeaves
                                     error:&error];

    NSEntityDescription *categoryEntity = [NSEntityDescription entityForName:@"Category"
                                              inManagedobjectContext:context];

    NSMutableArray *categories = [[NSMutableArray alloc] init];

    Nsstring *categoryPredicateString = [Nsstring stringWithFormat: @"category_id == $CATEGORY_ID"];

    nspredicate *categoryPredicate = [nspredicate predicateWithFormat:categoryPredicateString];


    for (NSDictionary *categoryKey in categoryResults){

        NSFetchRequest *categoryFetchRequest = [[NSFetchRequest alloc] init];

        [categoryFetchRequest setEntity:categoryEntity];

        NSNumber *categoryID = [NSNumber numberWithInt:[[categoryKey objectForKey:@"category_id"] integerValue]];

        [categories addobject:categoryID];

        NSDictionary *categoryVariables = [NSDictionary dictionaryWithObject:categoryID forKey:@"CATEGORY_ID"];

        nspredicate *catSubPredicate = [categoryPredicate predicateWithSubstitutionVariables:categoryVariables];

        [categoryFetchRequest setPredicate:catSubPredicate];

        NSArray *categoryArray = [[NSArray alloc] init];
        categoryArray = [context executeFetchRequest:categoryFetchRequest error:&error];

        Category *categoryObject = [categoryArray lastObject];
        NSNumber *categoryNum = [categoryObject valueForKey:@"category_id"];
        NSInteger categoryInt = [categoryNum integerValue];

        if (categoryInt != [[categoryKey objectForKey:@"category_id"] integerValue]){
            categoryObject = [NSEntityDescription
                              insertNewObjectForEntityForName:@"Category"
                              inManagedobjectContext:context];
            categoryObject.category_id = [NSNumber numberWithInt:[[categoryKey objectForKey:@"category_id"] intValue]];
        }
        if (categoryObject.category_name != [categoryKey objectForKey:@"category"]){
            categoryObject.category_name = [categoryKey objectForKey:@"category"];
        }

    }

    //Remove unneeded Categories from Core Data Store

    NSFetchRequest *removeUnusedCategories = [[NSFetchRequest alloc] init];
    [removeUnusedCategories setEntity:categoryEntity];
    NSArray *fetchedCategories = [context executeFetchRequest:removeUnusedCategories error:&error];

    for (Category *fetchedCategory in fetchedCategories){
        if (![categories containsObject:fetchedCategory.category_id]){
            [context deleteObject:fetchedCategory];
            NSLog(@"Object deleted");
        }
    }

    if (![context save:&error]) {
        NSLog(@"Whoops,Couldn't save: %@",[error localizedDescription]);
    }

[上下文保存]发生在后台MOC上,并通过通知中心同步到主MOC(在app委托中).它侦听NSManagedobjectContextDidSaveNotification并在主MOC上运行mergeChangesFromContextDidSaveNotification :.

第一次运行和第三次运行完美.它总是在第二次运行时发生.

我在iOS项目中使用Core Data,到目前为止除了一个问题之外它运行良好.

该应用程序从JSON文件填充Core Data存储,初始UITableViewController加载动画.但是,第二次启动应用程序时,初始UITableView为空白.我已经检查了多个位置,并且在第二次启动时数据位于Core Data存储中,但是没有调用UITableView或NSFetchedResultsController方法.

在第一次启动时,节中的行数返回0但在加载Core Data存储之后返回5应该.在第二次启动时,节中的行数(仅一个节)返回0并且不更新.在第三次和随后的所有启动中,该部分中的行数将返回5.

在第二次启动应用程序时,UITableView的cellForRowAtIndexPath和NSFetchedResultsController的didChangeObject方法都不会被调用. UITableViewController是UITableViewDelegate,UITableViewDataSource和NSFetchedResultsControllerDelegate.

正如核心数据准则中所建议的那样,app委托和表视图控制器共享一个托管对象上下文,而数据加载是在另一个线程中的后台MOC上完成的.当通过mergeChangesFromContextDidSaveNotification:调用上下文的save方法时,这些是同步的.

要重现,我从模拟器中删除应用程序,运行一次,数据库填充并正确显示应用程序.我停止应用程序并再次运行,没有任何显示.我停止应用程序并运行第三次并正确显示.

除了第二次启动应用程序外,所有这些似乎都能正常工作.第一次和第三次正常工作.我错过了什么?

至于我的代码,我不知道该放什么.让我们从UITableViewController的实现开始.

@implementation FTWTMasterViewController

@synthesize managedobjectContext;
@synthesize categoryController = _categoryController;
@synthesize catLocViewController;

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (NSFetchedResultsController *)categoryController {
    if (_categoryController != nil) {
        return _categoryController;
    }

    NSLog(@"tableview MOC = %@",self.managedobjectContext);

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Category" inManagedobjectContext:self.managedobjectContext];
    [fetchRequest setEntity:entity];

    NSSortDescriptor *sort = [[NSSortDescriptor alloc]
                              initWithKey:@"category_name" ascending:YES];
    [fetchRequest setSortDescriptors:[NSArray arrayWithObject:sort]];

    [fetchRequest setFetchBatchSize:20];

    NSFetchedResultsController *theFetchedResultsController =
    [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
                                        managedobjectContext:self.managedobjectContext
                                          sectionNameKeyPath:nil
                                                   cacheName:@"CategoryTable"];
    _categoryController = theFetchedResultsController;
    _categoryController.delegate = self;

    return _categoryController;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.tableView.dataSource = self;
    self.tableView.delegate = self;

    NSError *error;
    if (![[self categoryController] performFetch:&error]) {
        // Update to handle the error appropriately.
        NSLog(@"Unresolved error %@,%@",error,[error userInfo]);
        exit(-1);  // Fail
    }

    NSLog(@"Fetch called");

    self.title = @"Categories";
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    NSLog(@"number of sections = %lu",(unsigned long)[[self.categoryController sections] count]);
    return [[self.categoryController sections] count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    id  sectionInfo =
        [[_categoryController sections] objectAtIndex:section];

    NSLog(@"numberOfObjects = %lu",(unsigned long)[sectionInfo numberOfObjects]);
    return [sectionInfo numberOfObjects];
}

- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {
    Category *category = [_categoryController objectAtIndexPath:indexPath];
    cell.textLabel.text = category.category_name;
    NSLog(@"config cell %@",category.category_name);
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"tableView setup");
    static Nsstring *CellIdentifier = @"categoryCell";

    UITableViewCell *cell =
    [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    // Set up the cell...
    [self configureCell:cell atIndexPath:indexPath];

    return cell;
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    Category *aCategory = [self.categoryController objectAtIndexPath:indexPath];

    if (self.catLocViewController == nil){
        FTWTCatLocationViewController *aCatLocController = [[FTWTCatLocationViewController alloc] init];
        self.catLocViewController = aCatLocController;
    }

    self.catLocViewController.selectedCat = aCategory;
    aCategory = nil;

    self.catLocViewController.managedobjectContext = self.managedobjectContext;

    [self.navigationController pushViewController:self.catLocViewController animated:YES];

    self.catLocViewController = nil;
}

#pragma mark - Fetched results controller delegate
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
    // The fetch controller is about to start sending change notifications,so prepare the table view for updates.
    [self.tableView beginUpdates];
}

- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath {

    NSLog(@"didChangeObject");

    UITableView *tableView = self.tableView;

    switch(type) {

        case NSFetchedResultsChangeInsert:
            [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
            break;

        case NSFetchedResultsChangeDelete:
            [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
            break;

        case NSFetchedResultsChangeUpdate:
            [self configureCell:[tableView cellForRowAtIndexPath:indexPath] atIndexPath:indexPath];
            break;

        case NSFetchedResultsChangeMove:
            [tableView deleteRowsAtIndexPaths:[NSArray
                                               arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
            [tableView insertRowsAtIndexPaths:[NSArray
                                               arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
            break;
    }
}


- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id )sectionInfo atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type {

    switch(type) {

        case NSFetchedResultsChangeInsert:
            [self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
            break;

        case NSFetchedResultsChangeDelete:
            [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
            break;
    }
}


- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
    // The fetch controller has sent all current change notifications,so tell the table view to process all updates.
    [self.tableView endUpdates];
}

@end

解决方法

与我在上面的注释中假设的相反,如果指定了sectionNameKeyPath来创建表视图部分,则会发生相同的效果(我可以使用
一个测试程序).

当应用程序第一次启动时,会发生以下情况:

>创建持久性存储文件“appname.sqlite”.
>使用cacheName参数集创建表视图的获取结果控制器,以便创建节缓存文件.此时,所有部分都是空的.
>创建后台MOC,从资源文件中读取一些JSON数据并将对象添加到上下文中.
>保存背景MOC.

(顺便说一句,缓存文件是

Library/Caches/<bundle-id>/.CoreDataCaches/SectionInfoCaches/<tablename>/sectionInfo

在应用程序包中.)

第二次启动应用程序时,获取的结果控制器会检查部分信息缓存是否仍然有效或是否必须重新创建.根据文档,它比较了持久存储文件和节缓存文件的修改时间.

现在有趣的部分:如果(在第一次运行中)创建存储文件(步骤1)并保存更新的上下文(步骤4)发生在同一秒,那么商店文件的修改日期不会在步骤中更改4!

因此,部分缓存文件仍被视为有效且未重新创建.由于所有部分都是空的(在步骤2中),FRC使用此缓存信息并仅显示空部分.

后台MOC再次启动并保存上下文.现在,商店文件有一个新的修改日期,因此在应用程序的第三次运行中正确显示了部分和行.

为了确认我的“理论”,我在第一次和第二次运行之间手动“触摸”了商店文件,以强制执行更改的修改日期.然后正确显示所有部分和行.

(我仅在iPhone模拟器中对此进行了测试.我不知道HFS文件系统是否通常具有修改日期的1秒分辨率,或者sqlite是否在这里做了一些特殊的事情.我稍后会尝试对此进行调查.)

结论:如果创建存储文件并保存修改的数据在同一秒内发生,则必要时可能不会重新生成节信息缓存文件.

ios – 带有NSFetchedResultsController的UITableView不会第二次加载的更多相关文章

  1. ios – UITableView和Cell Reuse

    这是我的CustomCell类的init方法解决方法如果没有要显示的图像,则必须清除图像视图:

  2. ios – fetchedResultsController.fetchedObjects.count = 0但它充满了对象

    我正在使用相当标准的fetchedResultsController实现来输出tableView.在-viewDidLoad的最后,我正在进行第一次调用:这是我的fetchedResultsController:我的tableView方法:所以,问题是:在_fetchedResultsController.fetchedobjects.count的日志中等于0,但在视觉上tableView充满了对

  3. ios – UITableView在滚动时阻止重新加载

    或者你能想象一个防止这种行为的好方法吗?解决方法抱歉,我没有足够的声誉来添加评论,因此在单独的答案中回答您的上一个问题.-performSelector:withObject:afterDelay:延迟为0.0秒不会立即执行给定的选择器,而是在当前的RunloopCycle结束后和给定的延迟之后执行它.-performSelector:withObject:添加到当前Runloop循环中并执行.这与直接调用该方法相同.因此,使用-performSelector:withObject:afterDelay:

  4. ios – 在Swift中通过标记访问UITableViewCell内部的不同视图

    我正在尝试使用swift为iOS8制作应用程序.这里的目标是制作一种新闻源.此Feed显示来自用户的帖子,其遵循特定模式.我想过使用UITableView,其中每个单元格都遵循自定义布局.当我尝试访问其中的文本标签时出现问题.我尝试通过它的标签访问它,但是当我这样做时,整个应用程序崩溃了.报告的错误是“Swift动态转换失败”,我使用以下代码访问视图:难道我做错了什么?解决方法我认为问题是标签0.所有视图都是默认值0.所以尝试另一个标签值.

  5. ios – 如何实现`prepareForReuse`?

    解决方法尝试将此添加到您的MGSwipeTableCell.m:

  6. ios – 在UITableView上轻扫以删除以使用UIPanGestureRecognizer

    我使用以下代码将UIPanGuestureRecognizer添加到整个视图中:在主视图中我有一个UITableView,它有这个代码来启用滑动删除功能:只有RUNNING1打印到日志中,并且“删除”按钮不会显示.我相信其原因是UIPanGestureRecognizer,但我不确定.如果这是正确的,我该如何解决这个问题.如果这不正确,请提供原因并解决.谢谢.解决方法从document:Ifage

  7. viewWillAppear vs Viewdidload ios

    使用iOS导航应用程序的代码时,我遇到了麻烦:我在哪里可以为UITableView设置方法“initdata”?请帮帮我.解决方法您可以根据应用程序的需求放置initData,如果您的表需要每次使用新数据加载数据,那么它应该在否则,如果表需要通过单个数据重新加载,该数据不会发生变化或者没有对数据执行任何编辑操作,则应使用

  8. ios tableView reloadRowsAtIndexPaths无效

    解决方法包裹它怎么样?希望这可以帮助.

  9. ios – 我的表视图在滚动时在SWIFT中重用所选单元格

    实例变量

  10. ios – 重新加载表动画

    因此,当用户点击我的表格中的单元格时,我实际上并没有推送到新的视图控制器,而只是重新加载该tableView中的数据.但是,我希望得到一个效果类似于我推动新视图控制器时的效果.有没有人知道我如何将旧内容从屏幕上的旧内容和新内容放到屏幕上以获取整个表格?

随机推荐

  1. iOS实现拖拽View跟随手指浮动效果

    这篇文章主要为大家详细介绍了iOS实现拖拽View跟随手指浮动,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

  2. iOS – genstrings:无法连接到输出目录en.lproj

    使用我桌面上的项目文件夹,我启动终端输入:cd然后将我的项目文件夹拖到终端,它给了我路径.然后我将这行代码粘贴到终端中找.-name*.m|xargsgenstrings-oen.lproj我在终端中收到此错误消息:genstrings:无法连接到输出目录en.lproj它多次打印这行,然后说我的项目是一个目录的路径?没有.strings文件.对我做错了什么的想法?

  3. iOS 7 UIButtonBarItem图像没有色调

    如何确保按钮图标采用全局色调?解决方法只是想将其转换为根注释,以便为“回答”复选标记提供更好的上下文,并提供更好的格式.我能想出这个!

  4. ios – 在自定义相机层的AVFoundation中自动对焦和自动曝光

    为AVFoundation定制图层相机创建精确的自动对焦和曝光的最佳方法是什么?

  5. ios – Xcode找不到Alamofire,错误:没有这样的模块’Alamofire’

    我正在尝试按照github(https://github.com/Alamofire/Alamofire#cocoapods)指令将Alamofire包含在我的Swift项目中.我创建了一个新项目,导航到项目目录并运行此命令sudogeminstallcocoapods.然后我面临以下错误:搜索后我设法通过运行此命令安装cocoapodssudogeminstall-n/usr/local/bin

  6. ios – 在没有iPhone6s或更新的情况下测试ARKit

    我在决定下载Xcode9之前.我想玩新的框架–ARKit.我知道要用ARKit运行app我需要一个带有A9芯片或更新版本的设备.不幸的是我有一个较旧的.我的问题是已经下载了新Xcode的人.在我的情况下有可能运行ARKit应用程序吗?那个或其他任何模拟器?任何想法或我将不得不购买新设备?解决方法任何iOS11设备都可以使用ARKit,但是具有高质量AR体验的全球跟踪功能需要使用A9或更高版本处理器的设备.使用iOS11测试版更新您的设备是必要的.

  7. 将iOS应用移植到Android

    我们制作了一个具有2000个目标c类的退出大型iOS应用程序.我想知道有一个最佳实践指南将其移植到Android?此外,由于我们的应用程序大量使用UINavigation和UIView控制器,我想知道在Android上有类似的模型和实现.谢谢到目前为止,guenter解决方法老实说,我认为你正在计划的只是制作难以维护的糟糕代码.我意识到这听起来像很多工作,但从长远来看它会更容易,我只是将应用程序的概念“移植”到android并从头开始编写.

  8. ios – 在Swift中覆盖Objective C类方法

    我是Swift的初学者,我正在尝试在Swift项目中使用JSONModel.我想从JSONModel覆盖方法keyMapper,但我没有找到如何覆盖模型类中的Objective-C类方法.该方法的签名是:我怎样才能做到这一点?解决方法您可以像覆盖实例方法一样执行此操作,但使用class关键字除外:

  9. ios – 在WKWebView中获取链接URL

    我想在WKWebView中获取tapped链接的url.链接采用自定义格式,可触发应用中的某些操作.例如HTTP://我的网站/帮助#深层链接对讲.我这样使用KVO:这在第一次点击链接时效果很好.但是,如果我连续两次点击相同的链接,它将不报告链接点击.是否有解决方法来解决这个问题,以便我可以检测每个点击并获取链接?任何关于这个的指针都会很棒!解决方法像这样更改addobserver在observeValue函数中,您可以获得两个值

  10. ios – 在Swift的UIView中找到UILabel

    我正在尝试在我的UIViewControllers的超级视图中找到我的UILabels.这是我的代码:这是在Objective-C中推荐的方式,但是在Swift中我只得到UIViews和CALayer.我肯定在提供给这个方法的视图中有UILabel.我错过了什么?我的UIViewController中的调用:解决方法使用函数式编程概念可以更轻松地实现这一目标.

返回
顶部