0

我需要允许我的用户在 iPad 应用程序的文档目录中滚动浏览缩略图列表。当他们点击其中一个缩略图时,我需要知道哪个被点击了(或者让它调用一个方法,这基本上是同一件事。)

我知道如何将缩略图放在文档目录中,以及如何从那里读取它们。但我不确定哪个小部件最适合显示内容。是 UITableView 吗?CCScrollLayer?CCMenu高级?还有什么?

4

3 回答 3

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];
}
于 2013-07-04T16:29:57.927 回答
0

我在 cocos2d 项目上覆盖 UIScrollView 时遇到了各种问题。即使有所有建议的 hack,如果 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];
于 2013-07-14T03:34:31.397 回答
0

CCScrollLayer效果不如UIScrollView.

我使用视图来CCdirector添加UIkit

UIScrollView *scrollView = [UIScrollView alloc] init]; 
[[[CCDirector sharedDirector] view] addSubview:scrollView];

或添加UITableView.

于 2013-07-04T15:24:13.960 回答