简体   繁体   English

在xcode中读取和未读取消息

[英]read and unread messages in xcode

I am developing an iOS application that acts as a kind of email client. 我正在开发一个充当电子邮件客户端的iOS应用程序。 One of the views in my story board is an inbox in which displayed for each email: The sender of the message, the title of the conversation, the begining of the message body and the date & time at which the message was sent. 我的故事板上的一个视图是一个收件箱,其中为每封电子邮件显示:邮件的发件人,对话的标题,邮件正文的开头以及邮件的发送日期和时间。 (in tableView) How can I put these text in bold if the message isn't read yet, and in normal style after the user clic on the message ? (在tableView中)如果尚未阅读消息,如何将这些文本加粗显示,并在用户单击消息后以普通样式显示? Thank you ! 谢谢 !

- (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;

} }

Your table is loaded from a datasource in your app, this means that each email / message / or whatever you have contains its own properties (where you are reading the title from). 表格是从应用程序中的数据源加载的,这意味着每封电子邮件/消息/或任何您拥有的属性都包含其自己的属性(您从中读取标题)。 Add a flag there to indicate if it was already read or not, if it hasn't been read simply change the UILabel of the cell to show the title in bold. 在该处添加一个标志以指示是否已被读取,如果尚未被读取,则只需更改单元格的UILabel以粗体显示标题即可。
You have a method where you are returning a "UITableViewCell", it goes there. 您有一个要返回“ UITableViewCell”的方法,该方法在那里。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

2 things need to do : 1. save read / unread state on server side, if you want to save the result for all time. 需要做的两件事:1.如果要一直保存结果,则在服务器端保存已读/未读状态。 2. you have to set a key-value pair of isSelected (TRUE OR FALSE) at your end. 2.您必须在最后设置一个isSelected键值对(TRUE或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]];
]

}  

In cellForRowAtIndexPath : 在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;
}

Now in didSelectRowAtIndexPath : 现在在didSelectRowAtIndexPath中:

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

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

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

    }

You can use didSelectRowAtIndexPath method of tableView. 您可以使用tableView的didSelectRowAtIndexPath方法。

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //Mark that selected row as read...
    //you can change the elements in array
    //after change in array element plz reload tableView...
}

Hope this helps... 希望这可以帮助...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM