gpt4 book ai didi

iphone - 检查基于 PFRelation 的 PFTableViewCell

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

我在类别和项目之间有一个 PRelation 我希望制作一个 PFQueryTableViewController 用于将项目添加到类别。 PFQueryTableViewController 列出所有项目,用户选择要放入类别中的项目。我想弄清楚的是如何确定该项目是否在类别中并将 PFTableViewCell accessoryType 设置为 UITableViewCellAccessoryCheckmark

当前代码:

- (PFTableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {

static NSString * CellIdentifier = @"Cell";

BOOL itemInCategory = ?; //This is where I am determining the hierarchy

PFTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.textLabel.text = [sendingObject valueForKey:@"Title"];
cell.accessoryType = itemInCategory ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
return cell;

}

编辑

我还需要一些帮助从类别中删除项目:

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

BOOL itemInCategory = ?;

if (itemInCategory) {

//Remove Item?

} else {
PFRelation * relation = [sendingObject relationforKey:@"Items"];
[relation addObject:[self.objects objectAtIndex:[indexPath row]]];
[self save];
}

}

应该很简单

干杯

最佳答案

我遇到过类似的情况。我制作了一个容器来保存选定的 indexPaths。

@property (nonatomic, strong) NSMutableArray*selectedIndexPaths;

初始化选择容器

- (void)viewDidLoad
{
self.selectedIndexPaths = [@[] mutableCopy];
}

检查特定的indexPath是否存储在选择容器数组中

- (PFTableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {

static NSString * CellIdentifier = @"Cell";

BOOL itemInCategory = [self.selectedIndexPaths containsObject:indexPath];

PFTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.textLabel.text = [sendingObject valueForKey:@"Title"];
cell.accessoryType = itemInCategory ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
return cell;

}

如果 indexPath 存储在选择数组中,则从关系中删除项目,否则添加它并重新加载 tableView。

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

BOOL itemInCategory = [self.selectedIndexPaths containsObject:indexPath];
PFRelation * relation = [sendingObject relationforKey:@"Items"];

if (itemInCategory) {

//Remove the item from selectedIndex container and also relation
[self.selectedIndexPaths removeObject:indexPath];
[relation removeObject:self.objects[indexPath.row]];

}
else {

[self.selectedIndexPaths addObject:indexPath];
[relation addObject:self.objects[indexPath.row]];
[self save];
}

[tableView reloadData];

}

关于iphone - 检查基于 PFRelation 的 PFTableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14995790/

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