【发布时间】:2014-08-01 13:49:36
【问题描述】:
首先,我是编程新手,我正在尝试制作一个具有UITableView 并显示存储在数组中的名称并显示除每个名称之外的图像(图标)的应用程序。我在包中添加了三个图像,并将它们命名为 1.jpg、2.jpg 和 3.jpg。
应用程序运行良好,但在告诉应用程序我要显示存储在数组中的图像并运行应用程序后,iOS 模拟器首先可以工作,但随后我的 main.m 文件中出现绿色错误?
下面是我的实现文件:
NSMutableArray *myImages;
NSMutableArray *myNames;
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
myNames = [[NSMutableArray alloc ]initWithObjects:@"A",@"B",@"C", nil];
for (int imageNumber =1 ; imageNumber <= 3; imageNumber++) {
myImages= [[NSMutableArray alloc]initWithObjects:[[NSString stringWithFormat:@"%i.jpg", imageNumber ]], nil];
}
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return myNames.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:@"cell"];
cell.textLabel.text = myNames[indexPath.row];
//everything works fine until i add this line
cell.imageView.image = myImages [indexPath.row];
return cell;
}
【问题讨论】:
-
什么是绿色错误?
-
@MohitPopat 我在这里上传了我的照片app.box.com/s/u4biu37l7dsyl8474kur
-
你找到解决方案了吗?
-
@MohitPopat 是的,谢谢!
标签: ios objective-c uitableview