草庐IT

ios - Xcode 编译错误 "expected method to read array element not found on object of type NSArray"

coder 2024-01-25 原文

<分区>

我是 xcode 的新手,我尝试使用 UITableView 来显示数组中的内容。

我尝试在 Feed 中放置一些数组,并尝试在表格中显示它们。

但在这种情况下会提示错误

(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

在 cell.textLabel.text = self.imageTitleArray[indexPath.row];

它说读取数组元素的预期方法在 NSArray 类型的对象上找不到

我很困惑,为什么它不会读取数组,明显的船长请帮忙

这是我的H文件

#import <UIKit/UIKit.h>

@interface FeedTableViewController : UITableViewController
@property (strong, nonatomic) NSArray *imageTitleArray;
@end

这是我的M文件

#import "FeedTableViewController.h"

@interface FeedTableViewController ()

@end

@implementation FeedTableViewController



- (id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

if (self) {
    self.title = @"Feed";
    self.imageTitleArray = @[@"Image 1",@"Image 2",@"Image 3", @"Image 4",@"Image 5"];
}
return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];


}

- (void)viewDidUnload
{
    [super viewDidUnload];
    }

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

  return self.imageTitleArray.count;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  //  static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];

    if(cell==nil){
        cell= [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
    }
  cell.textLabel.text = self.imageTitleArray[indexPath.row];    
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}

@end

有关ios - Xcode 编译错误 "expected method to read array element not found on object of type NSArray"的更多相关文章

随机推荐