簡體   English   中英

iOS Core Data應用上的“預期類型”錯誤

[英]“Expected a type” error on iOS Core Data app

在我的iOS應用中,我收到以下錯誤:

預期類型

錯誤在第7行:

-(void)configureCell: (UITableViewCell *) cell atIndexPath:(NSIndexpath *) indexPath;

但我認為該方法在下面可以很好地實現。

請告訴我我在做什么錯。

#import "TodayListViewController.h"
#import "AppDelegate.h"
#import "ToDoPro.h"

@interface TodayListViewController ()

-(void)configureCell: (UITableViewCell *) cell atIndexPath:(NSIndexpath *) indexPath;

@end

@implementation TodayListViewController

@synthesize fetchedResultsController,managedObjectContext;
-(void) viewDidLoad {
    [super viewDidLoad];
    [self setTitle:@"Todays' TO-DOs"];
    [[self navigationItem] setLeftBarButtonItem:[self editButtonItem]];

    NSError * error =nil;
    if (![[self fetchedResultsController] performFetch:&error])
        {
            NSLog (@"Unresolved error %@, %@", error,[error userInfo]);
            abort();
        }
}

-(void) configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath*)indexPath
        {
            NSManagedObject *managedObject = [fetchResultsController objectAtIndexPath:indexPath];
            [[cell textLabel] setText:[[managedObject valueForKey:@"todotext"] description]];
            [[cell detailTextLabel] setText:[[managedObject valueForKey:@"thingDescription"]description]];
            [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        }


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [[fetchResultsController sections]count];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    id <NSFetchedResultsSectionInfo> sectionInfo = [[fetchResultsController sections] objectAtIndex:section];
    return [sectionInfo numberOfObjects];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"];
    }
    [self configureCell:cell atIndexPath:indexPath];
    return cell;
}

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete)
    {
        NSManagedObjectContext *context = [fetchResultsController managedObjectContext];
        [context deleteObject:[fetchResultsController objectAtIndexPath:indexPath]];
        NSError *error= nil;
        if (![context save:&error])
        {
            NSLog(@"Unresolved error %@,%@",error , [error userInfo]);
            abort();
        }
    }

}
-(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}
-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
    NSMutableArray *things = [[fetchedResultsController fetchedObjects]mutableCopy];

    NSManagedObject *thing = [[self fetchedResultsController] objectAtIndexPath:sourceIndexPath];

    [things removeObject:thing];

    [things insertObject:thing  atIndex:[destinationIndexPath row]];

    int i = 0;
    for (NSManagedObject *mo in things)
    {
        [mo setValue:[NSNumber numberWithInt:i++] forKey:@"displayOrder"];

    }
    things = nil;
    [managedObjectContext save : nil];

}

- (NSFetchedResultsController *) fetchedResultsController
{
    if (fetchedResultsController) return fetchedResultsController;
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc]init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"ToDoPro" inManagedObjectContext:managedObjectContext];

    [fetchRequest setEntity:entity];
    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"displayOrder" ascending:YES];
    NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
    [fetchRequest setSortDescriptors:sortDescriptors];

    NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:@"ThingsCache"];
    aFetchedResultsController.delegate = self;
    [self setFetchedResultsController:aFetchedResultsController];

    return fetchedResultsController;

}
@end

區分大小寫!

(NSIndexpath *)(NSIndexPath *)

第二個是已知類型(類),第一個是未知類型。 這就是為什么您得到“期望的類型”的原因,因為編譯器不知道NSIndexpath含義。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM