协议中的方法未实现

阿卜杜勒·拉米雷斯

在运行我的应用程序时,我收到一条错误消息,指出该方法-pilotDataviewcontollerDidCancel:未实现。

我遵循类似问题的指导,但未成功,我添加了它正在调用的另一个实现文件

#import <UIKit/UIKit.h>
#import "PilotData.h"

@protocol PilotDataViewControllerDelegate;

@interface PilotDataViewController : UIViewController

@property (weak, nonatomic) IBOutlet UITextField *nameField;
@property (weak, nonatomic) IBOutlet UITextField *phoneField;
@property (weak, nonatomic) IBOutlet UITextField *insuranceField;
@property (weak, nonatomic) IBOutlet UITextField *emailField;


@property (nonatomic, weak) id <PilotDataViewControllerDelegate> delegate;

@property (nonatomic, strong) PilotData *currentPilotData;

- (IBAction)cancel:(id)sender;
- (IBAction)save:(id)sender;

@end

@protocol PilotDataViewControllerDelegate
-(void)pilotDataViewControllerDidSave;
-(void)pilotDataViewControllerDidCancel:(PilotData *)pilotDataToDelete;
@end


#import <UIKit/UIKit.h>
#import "PilotDataViewController.h"

@interface ReleasesTableViewController : UITableViewController
<PilotDataViewControllerDelegate, NSFetchedResultsControllerDelegate>

@property (nonatomic, strong) NSManagedObjectContext *managedObjectContext;

@property (nonatomic, strong) NSFetchedResultsController *fetchedResultsController;

@end




//Releasestableviewcontroller.m


#import "ReleasesTableViewController.h"
#import "PilotData.h"

@interface ReleasesTableViewController ()

@end

@implementation ReleasesTableViewController

@synthesize fetchedResultsController = _fetchedResultsController;

-(void) PilotDataViewControllerDidCancel:(PilotData *)PilotDataToDelete {
    NSManagedObjectContext *context = self.managedObjectContext;
    [context deleteObject:PilotDataToDelete];

[self dismissViewControllerAnimated:NO completion:nil];}

-(void) pilotDataViewControllerDidSave {

    NSError *error = nil;
    NSManagedObjectContext *context = self.managedObjectContext;
    if (![context save:&error]) {
        NSLog(@"Error! %@", error);
    }
[self dismissViewControllerAnimated:NO completion:nil];}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    if ([[segue identifier] isEqualToString:@"pilotEntry"]) {
        //
        PilotDataViewController *acvc = (PilotDataViewController *)[segue destinationViewController];
        acvc.delegate =self;

        PilotData *newPilotData = (PilotData *) [[NSEntityDescription insertNewObjectForEntityForName:@"PilotData" inManagedObjectContext:[self managedObjectContext]];

        acvc.currentPilotData = newPilotData;
//    }
//
//    if ([[segue identifier] isEqualToString:@"showDetail"]) {
//        DisplayEditViewController *dvc = (DisplayEditViewController *) [segue destinationViewController];
//        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
//        Course *selectedCourse = (Course *) [self.fetchedResultsController objectAtIndexPath:indexPath];
//        dvc.currentCourse = selectedCourse;
//    }
}



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

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;

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



}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

    return [[self.fetchedResultsController sections]count];
}

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"pilotEntry";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    // Configure the cell...
    pilotData *pilotData = [self.fetchedResultsController objectAtIndexPath:indexPath];
    cell.textLabel.text = course.title;

    return cell;
}

-(NSString *) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    return [[[self.fetchedResultsController sections]objectAtIndex:section]name];
}

/*
 // Override to support conditional editing of the table view.
 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
 {
 // Return NO if you do not want the specified item to be editable.
 return YES;
 }
 */


// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        NSManagedObjectContext *context = [self managedObjectContext];
        pilotData *pilotDataToDelete = [self.fetchedResultsController objectAtIndexPath:indexPath];
        [context deleteObject:pilotDataToDelete];

        NSError *error = nil;
        if (![context save:&error]) {
            NSLog(@"Error! %@",error);
        }
    }

}


/*
 // Override to support rearranging the table view.
 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
 {
 }
 */

/*
 // Override to support conditional rearranging of the table view.
 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
 {
 // Return NO if you do not want the item to be re-orderable.
 return YES;
 }
 */
#pragma mark -
#pragma mark Fetched Results Controller section
-(NSFetchedResultsController *) fetchedResultsController {
    if (_fetchedResultsController != nil) {
        return _fetchedResultsController;
    }
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"pilotData"
                                              inManagedObjectContext:[self managedObjectContext]];
    [fetchRequest setEntity:entity];

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

    _fetchedResultsController = [[NSFetchedResultsController alloc]initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"pilotName" cacheName:nil];

    _fetchedResultsController.delegate = self;

    return _fetchedResultsController;
}

-(void) controllerWillChangeContent:(NSFetchedResultsController *)controller {
    [self.tableView beginUpdates];
}

-(void) controllerDidChangeContent:(NSFetchedResultsController *)controller {
    [self.tableView endUpdates];
}
-(void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath {

    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: {
            pilotData *changedpilotData = [self.fetchedResultsController objectAtIndexPath:indexPath];
            UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
            cell.textLabel.text = changedCourse.title;
        }
            break;

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

}

-(void) controller:(NSFetchedResultsController *)controller didChangeSection:(id<NSFetchedResultsSectionInfo>)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;
    }
}



#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.
    /*
     <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
     [self.navigationController pushViewController:detailViewController animated:YES];
     */
}

@end
斯维亚托斯拉夫·亚基米夫

ReleasesTableViewController应该从PilotDataViewControllerDelegate协议实现所有必需的方法-(void)pilotDataViewControllerDidCancel:ReleasesTableViewController课堂上实现方法

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

未在iOS中实现的协议中的方法

来自分类Dev

未在iOS中实现的协议中的方法

来自分类Dev

Xcode中的自动实现Swift协议方法

来自分类Dev

在基类中实现Swift协议方法

来自分类Dev

NSURLSessionDownloadTask的沉默未实现协议方法警告

来自分类Dev

协议可选方法在未实现时导致崩溃

来自分类Dev

协议方法未调用

来自分类Dev

检查是否在Swift中实现了可选的协议方法?

来自分类Dev

在Objective-C中实现协议特定的方法

来自分类Dev

未在协议中实现的方法(使用wit.ai SDK)

来自分类Dev

如何在Xcode中自动实现协议方法?

来自分类Dev

通过在超类中声明的方法实现协议?

来自分类Dev

如何在Xcode中自动实现协议方法?

来自分类Dev

实现UICollectionViewDataSource协议的最佳方法?

来自分类Dev

Clojure多方法/协议实现

来自分类Dev

Swift类“未实现(objc)协议”

来自分类Dev

未为“[object Object]”实现协议枚举

来自分类Dev

更好的解决方案,以处理未实现的协议所需方法

来自分类Dev

Midje中的模拟协议实现

来自分类Dev

错误-在Elixir中实现协议

来自分类Dev

特征中未实现方法的返回类型

来自分类Dev

在Android Studio中添加未实现的方法

来自分类Dev

特征中未实现方法的返回类型

来自分类Dev

Swift协议在基类中存在时允许未实现的功能

来自分类Dev

无法在 phoenix 中创建自定义链接:协议 Enumerable 未实现

来自分类Dev

协议扩展中的方法被调用而不是视图控制器中的方法实现

来自分类Dev

有没有最简单的方法在iOS中实现所有必需的协议方法?

来自分类Dev

在Swift中将协议实现者升级为协议的通用方法

来自分类Dev

协议中的方法

Related 相关文章

热门标签

归档