gpt4 book ai didi

ios - iOS 核心数据应用程序上的 "Expected a type"错误

转载 作者:行者123 更新时间:2023-11-28 20:10:36 25 4
gpt4 key购买 nike

在我的 iOS 应用程序中,我收到以下错误:

Expected a type

错误在第 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 的含义。

关于ios - iOS 核心数据应用程序上的 "Expected a type"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20445251/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com