ios - 如何制作UITableViewCell文本(如iOS版Facebook Messenger)?

标签 ios objective-c uitableview

当我们在Facebook Mesenger上收到消息时,在触摸单元格并查看消息后,该文本在UITableViewCell中变为粗体,然后返回到UITableView,该单元格文本不再为粗体。

如何产生这种行为?

在我的代码下面:

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

 [[fetchedObjects objectAtIndex:indexPath.row ] setValue:@"1" forKey:@"lido"];

    NSError*error;

    // Escreve no banco a alteração
    [context save:&error];

    for (int index = 0; index<[fetchedObjects count]; index++) {

        NSLog(@"%@",[[fetchedObjects objectAtIndex:index]valueForKey:@"lido"]);

.
.
.
// Implementation

}




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

//Implmentation

.
.
.

if ([[arrayProcessosLocal objectAtIndex:indexPath.row ]  valueForKey:@"lido"] == 1) {

        //Torna fonte bold
       cell.textLabel.font = [UIFont boldSystemFontOfSize:17];

      [cell.textLabel setText:[NSString stringWithFormat:@"%@ - %@", [processosLocal valueForKey:@"processo"],[processosLocal valueForKey:@"data_pdf"]]];

        return cell;
    }else{

        // Exibe a fonte normal caso o valor de "lido" seja 0 (zero)        
         [cell.textLabel setText:[NSString stringWithFormat:@"%@ - %@", [processosLocal valueForKey:@"processo"], [processosLocal valueForKey:@"data_pdf"]]];
        return cell;
    }

最佳答案

  • 您的模型对象应存储是否读取您的消息的状态。当邮件未读时,您的cell应该以粗体显示文本。状态更改时,请重新加载cell,并根据此状态对其进行配置。
  • 这是一个非常常见的模式。您在尝试实施它时是否遇到一些特别困难?
  • 关于ios - 如何制作UITableViewCell文本(如iOS版Facebook Messenger)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26670406/

    相关文章:

    iphone - UITableView 怪异!带图片

    ios - iOS11 中奇怪的 uitableview 行为。单元格向上滚动并带有导航推送动画

    ios - UIScrollView "out of frame"触摸区域无响应

    ios - swift 设计模式。为什么他们包括 Any, AnyObject

    objective-c - 如何计算两个地点之间的时差

    ios - 想要 UITableView 到 "snap to cell"

    ios - (DJIWidget) FFmpeg.framework 中的无效 CFBundleSupportedPlatforms 值 iPhoneSimulator

    ios - 首次运行时关键帧动画延迟

    ios - 错误 ITMS-9000 : invalid bundle. xyz.app 中的 bundle 不包含 bundle 可执行文件

    ios - 当 UITableView 滚动返回错误的 IndexPath.Row 值时