ios - 无法从 plist 获取内容到 UITableview

标签 ios iphone uitableview xcode6 plist

你好,我收到这个错误,我找不到问题出在哪里

我的代码是这样的:

@implementation ViewController {
NSDictionary *animalDetails;
NSArray *justAnimalNames;


- (void)viewDidLoad {
    [super viewDidLoad];
    NSURL *url = [[NSBundle mainBundle] URLForResource: @"animals"withExtension:@"plist"];
    animalDetails = [NSDictionary dictionaryWithContentsOfURL:url];
    justAnimalNames = animalDetails.allKeys;

    // Do any additional setup after loading the view, typically from a nib. }
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return animalDetails.count; }
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableView *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.textLabel.text = justAnimalNames [indexPath.row];

    return cell; }

我得到的错误是在这一行:

cell.textLabel.text = justAnimalNames [indexPath.row];

在“UITableview”类型的对象上找不到属性“textLabel”

有什么想法吗?

最佳答案

您的 cell 需要是 UITableViewCell * 而不是 UITableView *

关于ios - 无法从 plist 获取内容到 UITableview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30197937/

相关文章:

ios - 从 Storyboard中的 tableview 单元格多次显示 segue

ios - 在以编程方式添加的 UICollectionViewCell 中看不到 UILabel

ios - UIView - 什么覆盖将允许更新 UIView 框架

ios - 入门 - 创建一个通过蓝牙命令控制另一个(非 iOS)设备的 iPhone 应用程序

ios - 以编程方式添加的 ViewController 看起来已移动/转换(iOS、swift、 Storyboard)

iphone - 为什么 UItableViewCell 图像在滚动之前才加载?

objective-c - UITableView 滞后于第一次显示包含 UITextView 的单元格

ios - 在其他 View 前面添加来自 xib 的 View

iphone - 为什么我的 nsurl 请求没有出现在控制台中?

iPhone 返回按钮帮助