在xcode中读取和未读消息

时间:2014-08-14 08:11:33

标签: ios xcode

我正在开发一个充当电子邮件客户端的iOS应用程序。我的故事板中的一个视图是一个收件箱,其中显示了每封电子邮件: 消息的发送者,对话的标题,消息正文的开头和日期&消息发送的时间。 (在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;

}

3 个答案:

答案 0 :(得分:1)

您的表是从您应用中的数据源加载的,这意味着每个电子邮件/消息/或您拥有的任何内容都包含其自己的属性(您从中读取标题)。在那里添加一个标志以指示它是否已被读取,如果尚未读取,只需更改单元格的UILabel以粗体显示标题。
你有一个方法,你返回一个“UITableViewCell”,它去那里。

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

答案 1 :(得分:1)

需要做两件事: 1.如果要一直保存结果,请在服务器端保存读/未读状态。 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]];
]

}  

在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” ];

    }

答案 2 :(得分:0)

您可以使用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...
}

希望这会有所帮助......