gpt4 book ai didi

ios - 选择另一个表行时如何删除 UITableViewCellAccessoryCheckmark 的自定义图标

转载 作者:行者123 更新时间:2023-11-29 11:04:13 25 4
gpt4 key购买 nike

我使用以下代码将自定义图标添加到 UITableViewCellAccessoryCheckmark。问题是当触摸/选择另一行时,单元格复选标记不会取消选择

这是我的代码:

 - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

int index = indexPath.row; id obj = [listOfItems objectAtIndex:index];


//This toggles the checkmark
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];


if (cell.accessoryType == UITableViewCellAccessoryNone)
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;

UIImage *image = [UIImage imageNamed:@"icon-tick.png"];

UIButton *downloadButton = [UIButton buttonWithType:UIButtonTypeCustom];

[downloadButton setImage:image forState:UIControlStateNormal];
[downloadButton setFrame:CGRectMake(0, 0, 19, 19)];
[downloadButton setBackgroundColor:[UIColor clearColor]];
[self.tableView cellForRowAtIndexPath:indexPath].accessoryView = downloadButton;

//This sets the array

} else
{
cell.accessoryType = UITableViewCellAccessoryNone;

UIButton *downloadButton = [UIButton buttonWithType:UIButtonTypeCustom];
[downloadButton setTitle:@"" forState:UIControlStateNormal];
[downloadButton setFrame:CGRectMake(0, 0, 0, 0)];
[self.tableView cellForRowAtIndexPath:indexPath].accessoryView = downloadButton;

}

NSMutableData *data = [NSMutableData data];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
// Customize archiver here
[archiver encodeObject:obj forKey:@"keyForYourArrayOfNSIndexPathObjects"];
[archiver finishEncoding];
[[NSUserDefaults standardUserDefaults] setObject:data forKey:@"keyForYourArrayOfNSIndexPathObjects"];


NSKeyedUnarchiver *unarchiver;
unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:
[[NSUserDefaults standardUserDefaults] objectForKey:@"keyForYourArrayOfNSIndexPathObjects"]];
// Customize unarchiver here
countryItemSelected = [unarchiver decodeObjectForKey:@"keyForYourArrayOfNSIndexPathObjects"];
[unarchiver finishDecoding];

NSLog(@"list of items %@", countryItemSelected);

// Navigation logic may go here. Create and push another view controller.

CitiesViewController *detailViewController = [[CitiesViewController alloc] init];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];

}

谢谢你的帮助

最佳答案

“复选标记不会取消选择”到底是什么意思?无论如何:您可以使用委托(delegate)方法 tableView:didDeselectRowAtIndexPath: 并在取消选择单元格时将附件更改为不同的东西。

关于ios - 选择另一个表行时如何删除 UITableViewCellAccessoryCheckmark 的自定义图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14378196/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com