StackOverflow上的全新海报。我已经在这里阅读和学习了一段时间,但我需要开始提出几个问题并进行互动,所以对我的一些问题的任何帮助将不胜感激。
我基本上在cellForRowAtIndexPath中的plist的默认声音的tableView中生成一个列表。这会生成一个说“x”声音的列表,其中一个声音在其单元格上放置了默认的复选标记附件。我有一个plist文件存储'活动'声音文件的索引值,这是我在生成的tableView中放置原始复选标记的方式。因此,在下面的代码中,正如您所看到的,我加载了'活动'声音索引的plist值,但是,当用户与我的tableView交互并选择新声音时,我需要将默认选中标记放置为从视图中删除。其他一切都很好。我似乎无法解决这个简单的问题,我确定它是一个简单的语法问题,我只是不知道如何完成它。我确定解决方案是一行代码或两行代码,它在我的鼻子底下。提前感谢您的帮助。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *dictionarySound = [NSDictionary dictionaryWithContentsOfFile:[self ActDataFilePath]];
NSNumber *defaultSoundIndex = [dictionarySound valueForKey:@"soundIndex"];
int theIntVal = [defaultSoundIndex integerValue];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
//Everything below works just fine, checkmarks are removed and placed accordingly, sounds are played just fine. I just need help above in removing the default checkmark
if(self.checkedPath)
{
UITableViewCell *uncheckCell = [tableView cellForRowAtIndexPath:self.checkedPath];
uncheckCell.accessoryType = UITableViewCellAccessoryNone;
}
cell.accessoryType = UITableViewCellAccessoryCheckmark;
self.checkedPath = indexPath;
.......下面的其他代码点击播放我的声音,并将新活动的声音名称和索引值存储在plist中。
答案 0 :(得分:0)
处理此问题的常用方法是使用didSelectRowAtIndexPath:记录选择已更改的事实并告诉表视图重新加载数据(全部或仅受影响的单元格),然后在cellAtRowForIndexPath中执行accessoryType配置:
如果可以滚动表格,其他方式往往会失败。
答案 1 :(得分:0)
尝试以下代码
cell.accessoryType = UITableViewCellAccessoryNone;
答案 2 :(得分:0)
好男孩和女孩,这是我自己问题的解决方案。
当基于我的plist文件构建表时,确定复选标记并将其置于cellForRowAtIndexPath中。这是我的cellForRowAtIndexPath的代码,它抓取我的plist数据,构建我的表并使用复选标记设置默认选择。
NSDictionary *dicSound = [NSDictionary dictionaryWithContentsOfFile:[self ActDataFilePath]];
NSNumber *defaultSoundIndex = [dicSound valueForKey:@"soundIndex"];
//conversion of NSNumber to integer for comparison below to indexPath.row, both need to be int's
int theIntVal = [defaultSoundIndex integerValue];
static NSString *CheckMarkCellIdentifier = @"CheckMarkCellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: CheckMarkCellIdentifier];
cell.textLabel.text = [[MyArray objectAtIndex:indexPath.row] objectForKey:@"name"];
if(indexPath.row == theIntVal)
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
当用户通过单击另一个单元格并且didSelectRowAtIndexPath启动时与tableView交互时,这就是我放置新复选标记以及如何设置旧单元格没有附件复选标记的方式。
//This is a dictionary file that contains a number of values I need to grab
NSDictionary *dictionarySound = [NSDictionary dictionaryWithContentsOfFile:[self ActDataFilePath]];
NSNumber *defaultSoundIndex = [dictionarySound valueForKey:@"soundIndex"];
//conversion of NSNumber to integer for comparison below to indexPath.row, both need to be int's
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if(self.checkedPath)
{
UITableViewCell *uncheckCell = [tableView cellForRowAtIndexPath:self.checkedPath];
uncheckCell.accessoryType = UITableViewCellAccessoryNone;
}
cell.accessoryType = UITableViewCellAccessoryCheckmark;
self.checkedPath = indexPath;
//THE FIX
[tableView reloadData];
这里的关键是[tableView reloadData];在重新加载表时检查新选项并删除原始复选标记。显然,我正在重新加载数据,这意味着我在plist文件中内置了持久性。我基本上更新了本地词典的“声音索引”值。用户每次点击一个单元格,然后将其写入持久性plist文件。
希望这有助于解决此问题的其他任何人。