【发布时间】:2013-09-14 08:25:40
【问题描述】:
我是 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 版本低于 6.0。
-
是的,我的模拟器还在 5.1,不兼容吗?
-
是的,它与低于 6.0 的版本不兼容
标签: ios objective-c uitableview nsarray