如何使用NSLog显示对象数组

 dsvsV 发布于 2023-02-13 14:06

使用"NSLog"显示对象数组的解决方案是什么.

我可以用我的TableView显示它:

- (UITableViewCell *)tableView:(UITableView *)tableView
             cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        UITableViewCell *cell = [tableView
                                 dequeueReusableCellWithIdentifier:@"MyBasicCell2"];
        DataOrder *bug = [[[ArrayBuying instance] tableau] objectAtIndex:indexPath.row];
      static NSString *CellIdentifier = @"MyBasicCell2";
        CustomCellFinalView *Cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];


        if (!Cell) {
            Cell = [[CustomCellFinalView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        }

        Cell.NomProduit.text = bug.product;
        Cell.Quantite.text = [NSString stringWithFormat:@"%.2f €", bug.price];
        Cell.Prix.text = [NSString stringWithFormat:@"X %d  ", bug.quantite];

        return Cell;
        return cell;    
}

当我尝试我的ViewDidLoad:方法时

NSLog(@"%@",[[ArrayBuying instance] tableau]);

我在目标输出中获得:

(
    "",
    ""
)

非常感谢您的未来帮助

2 个回答
  • 试试这个

    for ( DataOrder *bug in [[ArrayBuying instance] tableau] ) 
    {
        NSLog(@"Product:- %@ Price:-%@", bug.product, bug.price);
    }
    

    2023-02-13 14:08 回答
  • 您可以- (NSString *)description在类DataOrder中实现方法.

    如果描述可用,NSLog将显示实例的描述方法的返回值.

    查看NSObject协议的文档https://developer.apple.com/library/mac/documentation/cocoa/reference/foundation/Protocols/NSObject_Protocol/Reference/NSObject.html

    通过实现描述方法,您可以更轻松地打印对象.

    2023-02-13 14:08 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有