最近几天我一直在搜索这个问题。
在我的文件 .h 中,我把它放在界面中:
NSMutableArray *newsCount;
@property (nonatomic, retain) NSMutableArray *newsCount;
在我的文件 .m 中我写了这段代码。
我已经在 View Will Appear 方法中分配了这个:
- (void)viewWillAppear:(BOOL)animated{
self.newsCount = [[NSMutableArray alloc] init];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.newsCount count];
// return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
cell.textLabel.text = [NSString stringWithFormat:@"- %@",[[newsCount objectAtIndex: indexPath.row] objectForKey:@"RELATED_CAPTION"]];
[cell.textLabel setFont:[UIFont fontWithName:@"Helvetica" size:13]];
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.numberOfLines = 2;
cell.textLabel.textColor = [UIColor grayColor];
return cell;
}
最佳答案
你如何设置 self.newsCount
?
要么您没有将数组放入 self.newsCount
,要么(更有可能)您正在设置“newsCount
”而不保留
它.
你在使用 ARC
吗?如果不是,你应该是。
关于ios - [__NSCFString 计数] : unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16392145/