gpt4 book ai didi

ios - xcode中的已读和未读消息

转载 作者:行者123 更新时间:2023-11-28 22:00:24 28 4
gpt4 key购买 nike

我正在开发一个用作电子邮件客户端的 iOS 应用程序。我的 Storyboard中的一个 View 是一个收件箱,其中为每封电子邮件显示:消息的发件人、对话的标题、消息正文的开头以及消息发送的日期和时间。 (在 TableView 中)如果尚未阅读消息,我如何将这些文本以粗体显示,并在用户点击消息后以正常样式显示?谢谢 !

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
messageTableViewCell *cell = (messageTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellidentifier];

// Configure Cell

NSDictionary *currentMessage = [self.unreadmessagesArray objectAtIndex:indexPath.row];

cell.nom.text = [currentMessage valueForKey:@"sentBy"];
cell.titre.text = [currentMessage valueForKey:@"messageThreadTitle"];
cell.resume.text = [currentMessage valueForKey:@"messageBody"];

cell.date.text = [currentMessage valueForKey:@"sentOn"];

return cell;

最佳答案

需要做两件事:1.在服务器端保存已读/未读状态,如果你想一直保存结果。2. 你必须在你的最后设置一个键值对 isSelected (TRUE OR FALSE)。

- (void) viewDidLoad {

// data coming from server keep in array having a dictionary

unreadmessagesArray = [[NSMutableArray alloc] init];
[unreadmessagesArray addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"value", @“someOtherkey", [NSNumber numberWithBool:FALSE], @"isSelected", nil]];
[unreadmessagesArray addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"value", @"someOtherkey", [NSNumber numberWithBool:FALSE], @"isSelected", nil]];
[unreadmessagesArray addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"value", @"someOtherkey", [NSNumber numberWithBool:FALSE], @"isSelected", nil]];
[unreadmessagesArray addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"value", @"someOtherkey", [NSNumber numberWithBool:FALSE], @"isSelected", nil]];
]

}

在 cellForRowAtIndexPath 中:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
messageTableViewCell *cell = (messageTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellidentifier];



NSDictionary *currentMessage = [self.unreadmessagesArray objectAtIndex:indexPath.row];

cell.nom.text = [currentMessage valueForKey:@"sentBy”];//someOtherkey
cell.titre.text = [currentMessage valueForKey:@"messageThreadTitle”];//someOtherkey
cell.resume.text = [currentMessage valueForKey:@"messageBody”];//someOtherkey

cell.date.text = [currentMessage valueForKey:@"sentOn”];//someOtherkey

if([currentMessage valueForKey:@“isSelected”]) {
[cell.titre setFont:[UIFont boldSystemFontOfSize:10]];

}
else {
[cell.titre setFont:[UIFont systemFontOfSize:10]];
}

return cell;
}

现在在 didSelectRowAtIndexPath 中:

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

NSDictionary *currentMessage = [self.unreadmessagesArray objectAtIndex:indexPath.row];

[currentMessage setValue:[NSNumber numberWithBool:YES] ForKey:@“isSelected” ];

}

关于ios - xcode中的已读和未读消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25303117/

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