Tag: 核心数据表

将新条目添加到每个新条目的表顶部的表视图控制器

我到目前为止有一个工作的应用程序,基本上包括以下内容: 使用核心数据,我有一个表视图控制器与添加button模式调用新的视图控制器提示用户添加文本到三个字段。 当用户点击保存时,该条目被添加到表格视图控制器中作为填充了信息的字幕单元。它运行良好。 我感到困惑并且一直在寻找答案的是,每个新条目都被添加到单元格的底部,所以如果有足够的单元格填充屏幕,新添加的条目将被添加到底部。 我真的很想得到每个新的条目到表格视图单元格的顶部。 我已经实现了按字母顺序sorting的sortDescriptors,但也是如此,但是我想要在表视图的顶部添加新的条目,而不pipe起始字符。 我的FetchRequest目前看起来像这样: NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Transaction"]; NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"whoBy.name" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)]; fetchRequest.sortDescriptors = [NSArray arrayWithObject:sortDescriptor]; self.transactions = [[managedObjectContext executeFetchRequest:fetchRequest error:nil]mutableCopy]; 这是将条目添加到数据库的代码: NSManagedObject *person = [NSEntityDescription insertNewObjectForEntityForName:@"Person" inManagedObjectContext:context]; [person setValue:self.nameTextField.text forKey:@"name"]; [transaction setValue:person forKey:@"whoBy"]; 任何想法将不胜感激!

使用NSFetchedResultsController移动行的方法及其委托不工作

我一直在试图按照这个教程重新安排在表视图中的行,而使用NSFetchedResultsController和NSFetchedResultsController委托,但我的项目是非常错误的。 会发生什么情况是,当我尝试重新排列一行并放下它时,这些行是随机的(可能不是随机的,但是我看不到模式来find问题)。 我的执行有什么问题? 表视图数据源: override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("RoutineCell", forIndexPath: indexPath) as! UITableViewCell var routine = fetchedResultsController.objectAtIndexPath(indexPath) as! Routine lastIndex++ // Configure the cell… cell.textLabel?.text = routine.name return cell } // Override to support conditional editing of the table view. override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: […]

iOS UITableView部分与fetchedResultsController混淆

我只有一个部分在一个表格视图中显示一个实体。 该实体有两个属性, workoutName和trainingLevel 。 两者都是stringtypes。 训练级别由三种types组成:1,2,3(trainingLevel =(整数16或stringtypes,哪一个是理想的?)我想将表格分成三个部分,每个部分包含相应训练级别的条目。 我该怎么做呢? 我目前使用的代码如下: – (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // Return the number of sections. return 1; } – (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // Return the number of rows in the section. return self.workoutType.workouts.count; } – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView […]