2013-07-04 94 views
0

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

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

+0

我会使用UITableView,以便单元应该重用自己,而不是与许多UIImages的开销内存。 – diegotrevisan

+0

@ sp4rkbr你能展示一个代码示例吗? – Eddy

回答

0

CCScrollLayer不起作用以及UIScrollView

我使用视图CCdirector添加UIkit

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

或添加UITableView

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]; 
} 
+0

你怎么称呼这个? – Eddy

+0

我的意思是从cocos2d项目中调用它。 – Eddy

+0

我不知道,你没有提到你的问题上的cocos2d。抱歉。 – diegotrevisan

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];