ios - [__NSCFString 计数] : unrecognized selector sent to instance

标签 ios objective-c uitableview

最近几天我一直在搜索这个问题。

在我的文件 .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/

相关文章:

ios - getDocuments() 函数多次获取相同的数据

ios - 键盘隐藏时键盘上方的工具栏不会隐藏

objective-c - 什么是发件人?

ios - 根据 subview 的宽高比使父 View 的高度灵活

ios - 自动布局 4 UILabels 垂直高度根据其内容/文本

ios - 亚马逊 AWS IOS SDK : How to list ALL file names in a FOLDER

iOS:应用程序打开时显示通知消息

ios - 如何在 Swift 中显示溢出到另一个单元格的单元格阴影

ios - 我什么时候应该重新加载数据()?

ios - 检测到按下后退以到达当前 View Controller