我现在正在处理一个奇怪的问题。我的应用程序部署目标设置为iOS6,因此我想同时支持iOS6和iOS7。
我只有一个简单的UITableView,用户可以在其中选择首选的通知声音。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
的代码是:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CheckmarkCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
[cell setTintColor:[UIColor redColor]];
if (indexPath.section == 0){
cell.textLabel.text = [_availableSounds objectAtIndex:indexPath.row];
if (indexPath.row == _checkedSoundIndexPath.row) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
}
else {
// Unrelated, another settings cell
cell.accessoryType = UITableViewCellAccessoryNone;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
return cell;
}
我的- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
如下所示:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section != 0) {
return;
}
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
[[self.tableView cellForRowAtIndexPath:indexPath] setAccessoryType:UITableViewCellAccessoryCheckmark];
if (_checkedSoundIndexPath != indexPath) {
[[self.tableView cellForRowAtIndexPath:_checkedSoundIndexPath] setAccessoryType:UITableViewCellAccessoryNone];
}
_checkedSoundIndexPath = indexPath;
}
问题是iOS7 iPhone不会按预期显示复选标记。在iOS6 iPhone上运行相同的代码按预期工作。我试图插入[cell setTintColor:[UIColor redColor]];
,但没有任何运气。即使我删除了所有与AccessoryType相关的代码并在我的故事板中添加了复选标记,也不会出现任何内容。请参阅下面的屏幕截图(首先是iOS6,第二个是iOS5)。
有没有人有想法?或者它是iOS7中的错误?
提前致谢!
修改
即使我创建了一个新的简单UITableViewController,只有5个单元,Accessory设置为UITableViewAccessoryTypeCheckmark,Checkmarks将不会出现在iOS7上。
答案 0 :(得分:10)
我有类似的问题,我解决了这个问题,改变了uitableview的色调
我将InterfaceBuilder的uint的tintcolot更改为Default color
或
tableView.tintColor = [UIColor blackColor];
答案 1 :(得分:4)
我和你有很长一段时间完全相同的问题。 在我的情况下,我实施了一些外观调整。其中一个是
[[UIView appearance] setTintColor:[UIColor whiteColor]];
尝试在您的项目中找到类似的全球事物。
答案 2 :(得分:2)
In my application it working perfect,check it
//take it in .h file mutable arSelectedRows;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
[cell setSelectionStyle:UITableViewCellSelectionStyleGray];
//Do anything you want for cell here
if([arSelectedRows containsObject:indexPath]) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if(cell.accessoryType == UITableViewCellAccessoryNone) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
[arSelectedRows addObject:indexPath];
}
else {
cell.accessoryType = UITableViewCellAccessoryNone;
[arSelectedRows removeObject:indexPath];
}
NSLog(@"id are here :%@",arSelectedIDs);
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
可能会有帮助。
答案 3 :(得分:0)
不,iOS 7中的 UITableViewCellAccessoryCheckmark 没有问题,请确保为其实现了正确的逻辑。
答案 4 :(得分:0)
我认为问题出在你的checksoundIndexpath上,请检查它是否有正确的索引路径,或者首先检查硬编码的索引路径。
您没有初始化checksoundindx路径。
此外,我注意到您没有将选定的行索引路径分配给_checkSoundIndexpath,只是检查两个索引路径(当前索引路径和_checksoundindexpath)是否相等,但如果它们不同,则应将选定的indedxpath分配给_checksound indexpath。 / p>
答案 5 :(得分:0)
在reloadRowsAtIndexPaths
方法中设置适当的数据之后,我宁愿重新加载tableview(最好只使用didSelectRowAtIndexPath:
)受影响的行。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Other logic..
[tableView deselectRowAtIndexPath:indexPath animated:NO]; // Would like to look for an alternative method to avoid this refresh??
NSMutableArray *reloadArray = [NSMutableArray arrayWithCapacity:2];
[reloadArray addObject:indexPath];
[reloadArray addObject:_checkedSoundIndexPath];
self.checkedSoundIndexPath = indexPath; // Should set this before reload
[tableView reloadRowsAtIndexPaths:reloadArray withRowAnimation:UITableViewRowAnimationAutomatic];
}
最重要的是,在cellForRowAtIndexPath:method -
中添加这些行- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// All your other code for this section followed by these lines...
if([_checkedSoundIndexPath compare:indexPath] == NSOrderedSame) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
// Other sections code
return cell;
}
答案 6 :(得分:0)
我可以通过设置Cell的色调来解决这个问题 它没有显示,因为白色的细胞色调和细胞选择方式是没有
cell.tintColor = [UIColor blackColor];
if(cell.selected){
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
}else{
[cell setAccessoryType:UITableViewCellAccessoryNone];
}
答案 7 :(得分:0)
我知道原始问题使用的是简单的http://myeducationhunt.com/schools
,但这可能适用于拥有自定义表格视图单元格的其他人。
我有一个自定义的UITableViewCell
子类。我尝试了一切,但勾选标记不会显示。最终我意识到我覆盖了UITableViewCell
,但忘了打电话给layoutSubviews
。这意味着复选标记无法正确显示。
[super layoutSubviews]