The*_*onz 1 arrays object objective-c ios
使用"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;
}
Run Code Online (Sandbox Code Playgroud)
当我尝试我的ViewDidLoad:方法时
NSLog(@"%@",[[ArrayBuying instance] tableau]);
Run Code Online (Sandbox Code Playgroud)
我在目标输出中获得:
(
"<DataOrder: 0x15d5d980>",
"<DataOrder: 0x15de1aa0>"
)
Run Code Online (Sandbox Code Playgroud)
非常感谢您的未来帮助
您可以- (NSString *)description在类DataOrder中实现方法.
如果描述可用,NSLog将显示实例的描述方法的返回值.
查看NSObject协议的文档https://developer.apple.com/library/mac/documentation/cocoa/reference/foundation/Protocols/NSObject_Protocol/Reference/NSObject.html
通过实现描述方法,您可以更轻松地打印对象.
试试这个
for ( DataOrder *bug in [[ArrayBuying instance] tableau] )
{
NSLog(@"Product:- %@ Price:-%@", bug.product, bug.price);
}
Run Code Online (Sandbox Code Playgroud)