Lon*_*don 1 objective-c ios ios5
我正在尝试创建水平滚动视图.每个视图包含一个图像.[done]
最初,当应用程序打开时,我会显示几个图像,即3,因此用户可以在图像之间来回滚动. [done]
但是我希望能够转到另一个视图控制器并选择另外两个图像(例如两个),并在滚动视图中显示五个图像,而不是最初显示3个.
如何做到这一点?要"重新刷新"初始滚动视图?
更新
我应该使用委托来进行视图控制器之间的通信吗?或者这是怎么做的?1个主控制器,其他包含图像选择?
这部分上面和更多的文章在这里解释.(不是广告,我希望它也会帮助某人).
赏金更新第1部分:
我想现在我找到了代表们的方法,我还有一些我无法找到答案的问题,我看到的所有例子都是关于更新表格视图的.
赏金第2部分:如果我在视图控制器中有一个滚动视图,在滚动视图中有一些nsimages.即:
- (void)viewDidLoad {
[super viewDidLoad];
NSMutableArray *images = ...some images array;
for (int i = 0; i < images.count; i++) {
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * i;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
UIImageView *subview = [[UIImageView alloc] initWithFrame:frame];
subview.image = [images objectAtIndex:i];
[self.scrollView addSubview:subview];
}
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * images.count, self.scrollView.frame.size.height);
}
Run Code Online (Sandbox Code Playgroud)
让我说我的视图控制器实现了一些委托方法didAddImage或didRemoveImage.
意味着关于images数组会更新.
实际赏金问题:
如何实际"告诉"视图控制器,现在你的滚动视图还有一个要显示的图像,请重新刷新还是重新加载?
如果我有一个表视图而不是滚动视图并插入图像我会这样做(在我的委托方法中):
-(void) mockDelegatetablemethod:(...) ...{
[self.images addObject:image];
NSIndexPath *indexPath =
[NSIndexPath indexPathForRow:[self.images count] - 1
inSection:0];
[self.tableView insertRowsAtIndexPaths:
[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationAutomatic];
[self dismissViewControllerAnimated:YES completion:nil];
}
Run Code Online (Sandbox Code Playgroud)
怎么会这样做滚动视图?
赏金更新第3部分:
这是上面描述的"简单"情况,当然我也必须支持删除图像,以及如果想要删除所有图像并添加一些新图像.
mat*_*way 10
如何实际"告诉"视图控制器,现在你的滚动视图还有一个要显示的图像,请重新刷新还是重新加载?
那么,您只需将新图像添加为滚动视图的子视图.所以类似于:
- (void)addImage:(UIImage*)image {
[images addObject:image];
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * images.count;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
UIImageView *subview = [[UIImageView alloc] initWithFrame:frame];
subview.image = image;
[self.scrollView addSubview:subview];
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * images.count, self.scrollView.frame.size.height);
}
Run Code Online (Sandbox Code Playgroud)
或者,您可以通过删除所有子视图然后重新添加图像数组中的所有图像来使用"重置"滚动视图的方法.然后调用此方法viewDidLoad而不是您的代码,这样您就不会复制代码.
基本上,这里没有银弹.你滚动自己.
| 归档时间: |
|
| 查看次数: |
5830 次 |
| 最近记录: |