我正在尝试构建一个函数来检查检索到的 JSON 值是否已更改(给定对话中的 messagecount
)。我正在使用 JSON 数据填充 TableView,并且希望将值存储在字典中,并在稍后进行数据更新时对它们进行比较。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
ConversationsModel* conversation = _feed.conversations[indexPath.row];
static NSString *identifier = @"ConversationCell";
UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
if (cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:identifier];
}
[self getMessageCountToDictionary:conversation.messagecount id:conversation.conversationid];
cell.textLabel.text = conversation.title;
return cell;
}
以及我将值存储在 NSMutableDictionary 中的方法:
- (void)getMessageCountToDictionary:(NSNumber*)messagecount id:(NSString *)conversationid
{
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
if (conversationid != NULL) {
[dictionary setValue:conversationid forKey:[NSString stringWithFormat:@"%@", conversationid]];
[dictionary setValue:messagecount forKey:@"messageCount"];
dictionaryCopy = [dictionary mutableCopy];
}
NSLog(@"Stored in dictionary %lu", (unsigned long)dictionary.count);
}
NSLog
返回 2
嗯,我不确定我的计划是否走在正确的轨道上。所有的投入都受到高度赞赏。
最佳答案
我建议使用键值观察器来观察您的对象更改值。
您可以在这里阅读更多相关信息:
关于ios - 从 TableView 行向 NSMutableDictionary 添加值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19397731/