【发布时间】:2015-01-23 19:23:08
【问题描述】:
我似乎无法理解为什么我不能显示单元格的标题和副标题。我已经尝试通过NSLog() 获取字符串对象,但除了NSLog() 之外,我没有收到任何输出,它成功打印了数组@987654324 中测试对象(Stack 对象)的内存位置@。
这是我的cellForRowAtIndexPath: 方法:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SimpleCell" forIndexPath:indexPath];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"SimpleCell"];
}
NSString *cell_Title = [[array_Stacks objectAtIndex:[indexPath row]] title];
NSString *cell_Subtitle = [[array_Stacks objectAtIndex:[indexPath row]] subject];
NSLog(@"%@", cell_Title);
NSLog(@"%@", [array_Stacks objectAtIndex:[indexPath row]]);
NSLog(@"%@", cell_Subtitle);
cell.textLabel.text = cell_Title;
cell.textLabel.tintColor = [cp color_master_tan];
cell.detailTextLabel.text = cell_Subtitle;
cell.detailTextLabel.tintColor = [cp color_master_tan];
//cell.imageView.image = [UIImage imageNamed:@"asset_Cell"];
return cell;
}
注意:“cp”是我的调色板对象,它返回一个UIColor 对象。
这里是 Stack.m
#import "Stack.h"
#import "FlashCard.h"
/*
Notes
* Need to get the name of the creator and add it to the default init.
*/
@implementation Stack
{
NSMutableArray *array_flashCard;
}
@synthesize title, subject, creator, array_FlashCard;
#pragma mark - Initializers
- (id)init {
return [self initWithTitle:@"New Stack" subject:@"No Subject" creator:@"None Listed" array:array_FlashCard];
}
- (id)initWithTitle:(NSString *) ttl subject:(NSString *) sbj creator:(NSString *) ctr array:(NSMutableArray *) arr {
self = [super init];
if (self) {
title = ttl;
subject = sbj;
creator = ctr;
array_FlashCard = arr;
title = [[NSString alloc] init];
subject = [[NSString alloc] init];
creator = [[NSString alloc] init];
array_FlashCard = [[NSMutableArray alloc] init];
}
return self;
}
#pragma mark - Array Operations
- (void)addFlashCardToArray:(FlashCard *) flashcard { [array_FlashCard addObject:flashcard]; }
@end
【问题讨论】:
-
字符串为空。
-
首先,它被调用了吗?设置一个断点,看看它是否被触发。如果没有,您将什么设置为表格视图的数据源?您的方法是否被调用,表明表中有多少行?如果是,它会返回什么?
-
第二个 NSLog 打印出正确的信息,即数组中 Stack 对象的内存地址,所以我知道该对象存在并且该方法正在被触发。文件的所有者已设置。问题是,即使字符串为空,我至少会在终端中得到带有时间戳的“nil”,但我什么也得不到。
-
不,字符串是有效的对象,但它们是空的。
nil与空字符串不同,NSLog()将不会打印任何内容,如果您提供的只是一个空字符串。
标签: ios objective-c cocoa-touch nslog