【发布时间】:2013-12-24 12:17:43
【问题描述】:
与我一起工作的一组程序员,我有一个带有 TableViewController 的故事板,它显示了我们从日期选择器中编码的 UILocalNotifications 列表。它们都有不同的时间,并且每次设置提醒以及提醒文本时,时间戳都会显示在表格视图单元格中。目前,提醒按时间顺序(设置它们的顺序)显示。触发 localNotification 后,带有旧提醒的单元格将自动清除。到目前为止,这一切都取得了成功。
问题在于最后一个小函数。由于正在制作的提醒应用程序设计为可定制的,我们希望用户能够移动单元格。作为一个团队,我们在允许用户编辑订单方面取得了成功,但面临另一个困境。一旦更改了订单并且用户离开视图(该应用是基于导航栏的)并返回到视图,订单将默认恢复为原始订单,而不是他们从移动单元格输入的自定义订单。
所以,问题来了(希望下面关于我们如何在表格视图中输入数据的代码能够提供一些上下文)。我的小组想知道,我们如何根据列表保存和加载用户修改单元格在表格中的位置。您可能会在我们的代码中注意到,提醒列表纯粹是按时间顺序排列的,只需调用 UILocalNotification 类即可。我们是否应该获取每个单独单元格的参数并将它们保存到一个数组中,然后以某种方式加载它们?对此问题的反馈将不胜感激。我还提供了几个屏幕截图,希望能让您了解最终用户方面正在发生的事情。
我们作为一个组输入了要编辑的参数如下:
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
我们还有以下功能可以移动表格单元格:
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
支持重新排列表格视图单元格。这是输入代码保存仓位的最佳方法吗? UITableView 有没有可以保存和加载表格状态的属性?另外,如果我们需要将本地通知转换为字符串的形式,这样做的语法是什么?
这就是将信息输入到表格视图中的方式。添加了一些适用的注释。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Get list of local notifications
NSArray *localNotifications = [[UIApplication sharedApplication] scheduledLocalNotifications];
UILocalNotification *localNotification = [localNotifications objectAtIndex:indexPath.row];
// Display notification info
NSDate *date = localNotification.fireDate;
NSDateFormatter *formatter1 = [[NSDateFormatter alloc] init];
[formatter1 setDateFormat:@"dd/MM/yyyy"];
NSString *dateFormatter = [formatter1 stringFromDate:date];
NSDateFormatter *formatter2 = [[NSDateFormatter alloc] init];
[formatter2 setDateFormat:@"EEEE hh:mm"];
NSString *dateFormatter2 = [formatter2 stringFromDate:date];
NSString *on = [dateFormatter2 stringByAppendingString:@" on the "];
NSString *final = [on stringByAppendingString:dateFormatter];
[cell.textLabel setText:localNotification.alertBody];
if (final.length != 8) {
[cell.detailTextLabel setText:final];
}
else {
[cell.detailTextLabel setText:@""];
}
return cell;
}
就应用程序的屏幕截图而言。这就是我们所拥有的。我们有一个编辑参数,并且在带有导航栏的 tableviewcontoller 中设置了单元格。主视图(如最上方的屏幕截图所示)是输入文本的位置。然后在选择日期选择器日期(或预设)时将其作为 UIlocalnotification 输入
感谢您抽出宝贵时间回答这个问题。
【问题讨论】:
-
从哪里获取 tableview 的信息(您是否使用 DB)
-
我从 date picker.date 获取它(在未显示的视图中)并获取从 textField 输入的文本。然后将其保存为带有时间和文本的本地通知数组。
-
在重新排列单元格时,您需要重新排列阵列(本地通知阵列)。声明应该像..我会在答案中显示它请检查它
标签: ios uitableview tableview cell