我有一个NSArray
(self.allUsers
)内有PFUser
个对象:
"<PFUser: 0x7ff578f501f0, objectId: qvFwzbBGky, localId: (null)> {\n friends = \"<PFRelation: 0x7ff578f4eef0, 0x0.(null) -> _User>\";\n phone = 0;\n surname = test;\n username = \"test@gmail.com\";\n}"
我可以使用[self.allUsers valueForKey:@"phone"]
我有另一个NSArray
(self.sectionedPersonName
),里面有NSObject
人(按部分排序)。我可以使用person.number
访问电话号码。
我想比较这两个阵列之间的电话号码。并在匹配PFUser
objectId([self.allUsers valueForKey:@"objectId"];
)
也许我使用NSPredicate
CONTAINS?
我不知道NSObject和PFUser是否可行。
之后,我想改变匹配的细胞的颜色。
在didSelect中,当我点击它时,只需从PFUser
中记录objectId。我们必须在PFUser和NSObject之间建立对应关系......
我成功显示匹配的PFUser的objectId:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryNone;
Person *person = [[self.sectionedPersonName objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
cell.textLabel.text = person.fullName;
cell.detailTextLabel.text = person.number;
if ( [[self.allUsers valueForKey:@"phone"] containsObject:person.number] ) {
// do found
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
Person *person = [[self.sectionedPersonName objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
__block PFUser *foundedPFUser;
NSMutableArray *realResult = [NSMutableArray new];
[self.tableData enumerateObjectsUsingBlock:^(Person *obj, NSUInteger idx, BOOL *stop) {
NSArray *result = [self.allUsers filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"%K = %@", @"phone", obj.number]];
if(result.count){
[realResult addObjectsFromArray:result];
}
}];
NSLog(@"%@",realResult);
if (cell.accessoryType == UITableViewCellAccessoryCheckmark){
NSLog(@"%@", person.number);
}
else{
}
现在,当我点击一个单元格时,那个日志:
记录:
2015-08-31 12:02:59.727 ChillN[691:18988] (
"<PFUser: 0x7f992a4df7e0, objectId: bEO3D62Cvo, localId: (null)> {\n friends = \"<PFRelation: 0x7f992a4a3b60, 0x0.(null) -> _User>\";\n phone = 5555228243;\n surname = test4;\n username = \"test4@gmail.com\";\n}",
"<PFUser: 0x7f992a4a3d30, objectId: rlG21mKFJZ, localId: (null)> {\n friends = \"<PFRelation: 0x7f992a4e08d0, 0x0.(null) -> _User>\";\n phone = 31560987;\n surname = test2;\n username = \"test2@gmail.com\";\n}",
"<PFUser: 0x7f992a47af90, objectId: 7X0OVanRZ9, localId: (null)> {\n friends = \"<PFRelation: 0x7f992a4e0970, 0x0.(null) -> _User>\";\n phone = 7075551854;\n surname = test3;\n username = \"test3@gmail.com\";\n}"
)
2015-08-31 12:02:59.727 ChillN[691:18988] 5555228243
现在我希望那场比赛只有好PFUser
。当我点击&#34; Anna Haro&#34;时,发现person.number
5555228243 ,并在PFUser
&#34; 5555228243&#34;中找到,记录PFUser
的objectId。
我期待的是:
记录:
2015-08-31 12:02:59.727 ChillN[691:18988] (
"<PFUser: 0x7f992a4df7e0, objectId: bEO3D62Cvo, localId: (null)> {\n friends = \"<PFRelation: 0x7f992a4a3b60, 0x0.(null) -> _User>\";\n phone = 5555228243;\n surname = test4;\n username = \"test4@gmail.com\";\n}"
)
2015-08-31 12:02:59.727 ChillN[691:18988] 5555228243