问题描述
我看过很多例子,但我仍然没有设法让我的工作。
我有 1 个从 NSUserDefaults 填充的数组。一切正常。但是我希望能够将一行移动到空的顶部。就像固定笔记一样。
我可以移动并保存当前部分中的行,但移动不会应用更改。
相关代码:
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
//if (sourceIndexPath.row != destinationIndexPath.row && sourceIndexPath.section != destinationIndexPath.section) {
//return;
if ( sourceIndexPath.row != destinationIndexPath.row )
{
id noteObject = [self.noteArray objectAtIndex:sourceIndexPath.row];
self.noteArray = [noteArray mutablecopy];
[self.noteArray removeObjectAtIndex:sourceIndexPath.row];
[self.noteArray insertObject:noteObject atIndex:destinationIndexPath.row];
id dateObject = [self.dateArray objectAtIndex:sourceIndexPath.row];
self.dateArray = [dateArray mutablecopy];
[self.dateArray removeObjectAtIndex:sourceIndexPath.row];
[self.dateArray insertObject:dateObject atIndex:destinationIndexPath.row];
[self performSelector:@selector(delayedReloadData:) withObject:self.tableView afterDelay:0.02];
return;
}
}
- (void)delayedReloadData:(UITableView *)tableView
{
[[NSUserDefaults standardUserDefaults] setobject:self.noteArray forKey:@"note"];
[[NSUserDefaults standardUserDefaults] setobject:self.dateArray forKey:@"date"];
[[NSUserDefaults standardUserDefaults] synchronize];
[self.tableView reloadData];
NSLog(@"Move Row Update");
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
NSInteger numOfSections;
if ([self.noteArray count])
{
tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
numOfSections = 2;
tableView.backgroundView = nil;
}
else
{
UILabel *noDataLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,tableView.bounds.size.width,tableView.bounds.size.height)];
noDataLabel.text = @"No data available";
numOfSections = 1;
noDataLabel.textColor = [UIColor systemGrayColor];
noDataLabel.textAlignment = NSTextAlignmentCenter;
tableView.backgroundView = noDataLabel;
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
return numOfSections;
}
这可能是问题吗?不知道如何解释空白部分
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == 0) {
return;
}
if (section == 1) {
return [self.noteArray count];
}
return section;
}
任何帮助将不胜感激。谢谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)