我不确定我是否正确执行此操作,但本质上我想在控制器加载时实例化我的 uiimageviews。之后,当我实现在计时器上执行的方法时,我想根据索引获取 uiimageview 的引用并将其添加到视图中。
我正在使用 NSMutableDictionary。我将所有代码都放在同一个方法中,只是为了测试它。不应该 [self.view addSubview:poster]; 将第一张图像放在当前视图中?
self.images = [NSMutableDictionary dictionary];
CGRect imageFrame = CGRectMake(0.0, 0.0, 1024.0, 280.0);
UIImageView *image_one = [[UIImageView alloc] initWithFrame:imageFrame];
image_one.image = [UIImage imageNamed:@"image_one.png"];
NSString *theKey = [NSString stringWithFormat:@"%d",0];
[self.images setObject:image_one forKey:theKey];
UIImageView *image_two = [[UIImageView alloc] initWithFrame:imageFrame];
image_two.image = [UIImage imageNamed:@"image_two.png"];
NSString *theKey1 = [NSString stringWithFormat:@"%d",1];
[self.images setObject:image_two forKey:theKey1];
UIImageView *poster = (UIImageView *)[self.images objectForKey:0];
[self.view addSubview:poster];