我需要允许我的用户滚动浏览iPad应用程序上文档目录中的缩略图列表。当他们点击其中一个缩略图时,我需要知道哪一个被点击(或者让它调用一个方法,这基本上是相同的。)
我知道如何将缩略图放在文档目录中,以及如何从那里读取它们。但我不确定哪个小部件最适合显示内容。是UITableView吗? CCScrollLayer? CCMenuAdvanced?别的什么?
答案 0 :(得分:0)
CCScrollLayer
与UIScrollView
的效果不同。
我使用CCdirector
视图添加UIkit
。
UIScrollView *scrollView = [UIScrollView alloc] init];
[[[CCDirector sharedDirector] view] addSubview:scrollView];
或添加UITableView
。
答案 1 :(得分:0)
在一个数组中获取缩略图的所有路径,让我们调用pathsArray
NSArray *pathsArray = [seld getPathsForAllImages];
现在实现UITableViewDataSource和UITableViewDelegate:
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [pathsArray count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
NSString *pathForImage = [pathsArray objectAtIndex:indexPath.row];
cell.imageView.image = [UIImage imageWithContentsOfFile:pathForImage];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *pathForImage = [pathsArray objectAtIndex:indexPath.row];
}
答案 2 :(得分:0)
我在cocos2d项目上覆盖UIScrollView时遇到了各种各样的问题。即使有所有建议的黑客攻击,如果cocos2d中的单个帧占用太长时间,UIScrollView也会停止正常工作。我怀疑UITableView也会发生这种情况。
为了解决我自己的问题,我创建了一个自定义ScrollNode类。它真的很容易使用:
// create the scroll node
ScrollNode *scrollNode = [ScrollNode nodeWithSize:CGSizeMake(size.width, size.height)];
[self addChild:scrollNode];
// Generate some content for the scroll view
// add it directly to scrollView, or to the built in menu (scrollView.menu)
[scrollNode.menu addChild:yourMenuItem];
// Set the content rect to represent the scroll area
CGRect contentRect = [scrollNode calculateScrollViewContentRect];
[scrollNode setScrollViewContentRect:contentRect];