objective-c - IOS中的即时/自动保存

标签 objective-c ios uitableview uitextfield modal-dialog

背景:在我的日常工作中,我是一名 Windows 自动化和数据翻译“专家”(或者他们这么说)。自从我在 2004 年购买了我的第一台 Mac 以来,我一直在不断地涉足 Objective-C 编码。

我正在开发一个 IOS 应用程序。我的数据容器类知道如何从磁盘保存和加载,每个对象都响应 -(void)saveToImpliedFilename{} 的实例方法或 -(void)save:(NSString *)filename {} .有一个静态调用来从存储中加载数据文件并从中创建不同的数据对象(它们是相当轻量级的对象,所以我不担心一次加载几个)。该应用程序的域如此之大,以至于其中许多都不会一次加载。

+(NSArray *)loadData {}

这一切都很好,很棒。在存储中,对象以 Xml 形式存储,并且生命周期很好。

我遇到麻烦的地方是尝试修改教程时,我会发生两件事:

快速说明:我将本教程用作 POC 编码的基础,然后我将返回并从“真实”编码重新开始,重用我的数据对象和我在此过程中构建的一些其他实用程序。

这是我的目标和问题 list :
  • 我希望表格 View 告诉数据对象在几乎每个“编辑”事件中保存。我唯一能一直工作的就是重新组织 table 的顺序。 (保存按钮和添加新条目可以正常工作)
  • 在列表中输入一个新条目会创建一个漂亮的模态编辑器,其中包含一个保存和取消按钮,效果非常好。但是,如果我编辑现有条目,则无法重现保存按钮的行为。每次我尝试时,按钮的事件都不再触发。我不知道我哪里错了。

  • 我使用本教程系列中的“可编辑 TableView ”项目作为我的基础:http://www.aboutobjects.com/community/iphone_development_tutorial/tutorial.html

    在下面的代码中,[self isModal] 测试是让保存/取消按钮可见并连接起来的地方。调出新条目屏幕显然是它唯一的模态。我尝试将这些东西连接起来,以便始终创建按钮,但同样,事件永远不会为任何一个触发。下面的下一个 block 是使用 NEW 功能显式调用可编辑 TableView 的地方,但同一 TableView 的非模态视图由选择器表上的选择事件调用。

    所以...
    // code snipped for the new/modal editor
    
    - (void)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;
    
        //  If the user clicked the '+' button in the list view, we're
        //  creating a new entry rather than modifying an existing one, so
        //  we're in a modal nav controller. Modal nav controllers don't add
        //  a back button to the nav bar; instead we'll add Save and
        //  Cancel buttons.
        //
        if ([self isModal]) {
            UIBarButtonItem *saveButton = [[UIBarButtonItem alloc]
                                           initWithBarButtonSystemItem:UIBarButtonSystemItemSave
                                           target:self
                                           action:@selector(save)];
    
            [[self navigationItem] setRightBarButtonItem:saveButton];
    
            UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc]
                                             initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
                                             target:self
                                             action:@selector(cancel)];
    
            [[self navigationItem] setLeftBarButtonItem:cancelButton];
        }
        // do stuff here to display my object...    
    
    }
    
    // this code is called from the selection table to explicitly add a new data object. 
    
    - (void)add {
    
        vhAddVehicleViewController *controller = [[vhAddVehicleViewController alloc] initWithStyle:UITableViewStyleGrouped];
    
        id vehicle = [[Vehicle alloc] init];
        [controller setVehicle:vehicle];
        [controller setListcontroller:self];
    
        UINavigationController *newNavController = [[UINavigationController alloc] initWithRootViewController:controller];
    
        [[self navigationController] presentViewController:newNavController animated:YES completion:nil];
    
    }
    
    
    // this is where it's called on the table selection to show the same view without the save/cancel buttons.
    
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        vhAddVehicleViewController *controller = [[vhAddVehicleViewController alloc] initWithStyle:UITableViewStyleGrouped];
    
        NSUInteger index = [indexPath row];
        id vehicle = [[self vehicles] objectAtIndex:index];
    
        [controller setVehicle:vehicle];
        [controller setTitle:[vehicle Vehiclename]];
    
        [[self navigationController] pushViewController:controller animated:YES];
    }
    

    我假设问题是呈现它会使其成为模态,而插入它不会......?没关系。但是当我对模态进行测试以尝试使按钮保持工作时,我感到很高兴。按钮在点击时绘制并单击,但事件不会触发。

    停! :-)
    非常感谢。
    -- Chris(我使用我的 Google 帐户登录,所以在页面顶部我显示为“user1820796”)耸了耸肩

    最佳答案

    您忘记调用 [super viewDidLoad];

    关于objective-c - IOS中的即时/自动保存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13361108/

    相关文章:

    iphone - 如何将 NSIndexPath 转换为 NSInteger?

    ios - 重新连接到断开连接的对等体

    ios - 使用单独的类在 Swift 中处理 Alamofire 对 TableView 的响应的最佳方法是什么?

    ios - UITableViewAutomaticDimension 不适用于 UIImageView

    objective-c - iOS 6 UILocalNotification

    objective-c - 如何在 RubyMotion 中实现 OSX 上的图像按钮?

    ios - 如何在ios上实现RabbitMq?

    ios - 如何使用 Objective-C 创建和使用对象?

    iphone - 内部有 3 个选项卡且没有工作标题的导航 Controller

    ios - 截图 UIImageView 和 UILabel 然后分享