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

我是xcode的新手,我嘗試與UITableView一起展示 array 中的內容。

我嘗試在裡面放一些 array,並嘗試在表中顯示它們。

但是這個例子暗示了這個錯誤

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

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

它表示在NSArray類型的對象上沒有找到讀取 array 元素的預期方法

我很困惑,為什麼它不讀 array,原因如下:
.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

解决方法如下:
直接把字典的值赋值给tableviewcell行的值就可以了


cell.textLabel.text = [self.imageTitleArray objectAtIndex: indexPath.row]; 
NSDictionary *jsonDict = [_temp objectAtIndex:indexPath.row];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。