2011-11-05 34 views
0

我有一个AQGridView设置为显示文档目录中的文件以及其他4个预定义并在启动时加载到表中的文档。我需要知道如何设置单元格来保存文档的URL(是的,即使是预定义的!他们都只是NSStrings毕竟。),所以它能用NSString在AQGridViewCell中

- (void)gridView:(AQGridView *)gridView didSelectItemAtIndex:(NSUInteger)index { 
    NSString *fileURL = [self._icons objectAtIndex:index]; 
    // do stuff 
} 

和加载被称为用自定义的-(id)init方法进入新视图。目前,文档目录对象单元格的NSLog在日志中返回(NULL)SIGABRT


好的,赏金到了。我认为这意味着我可以要求一点质量。代码片段会很棒!

可根据要求提供代码。

编辑工作代码:

//.h  
NSMutableArray *_documentIconsURLs; 

//.m 
//viewDidLoad 
// array for internal and external document URLs 
    self._documentIconsURLs = [NSMutableArray array]; 
     _documentIconsURLs = [[NSMutableArray alloc] initWithObjects:@"Musette.pdf", 
           @"Minore.pdf", 
           @"Cantata.pdf", 
           @"Finalé.pdf", 
           @"divine-comedy-inferno.pdf", nil]; 
//didSelectObject 
- (void) gridView:(AQGridView *)gridView didSelectItemAtIndex:(NSUInteger)index { 

    NSLog (@"Selected theArgument=%d\n", index); 

    UIViewController *viewController = [[[UIViewController alloc]init]autorelease]; 
    { 
     //if file is built-in, read from the bundle 
     if (index <= 4) 
     { 
      // first section is our build-in documents 
      NSString *fileURLs = [_documentIconsURLs objectAtIndex:index]; 
      NSLog(@"%@", fileURLs); 
      viewController = [[[viewController alloc]initWithContentURL:fileURLs]autorelease]; 
     } 

回答

1

对与AQGridView未来的跳板示例代码看看。

与交流的代码SpringBoardIconCell和SpringBoardViewController代码我放在这里:https://gist.github.com/52c61b9c68e482ec35a1

基本上只需要添加一个UILabel到SpringBoardIconCell,将其添加到视图层级结构,并设置于从数据源中gridView:cellForItemAtIndex:文本。

最后:

-(void)gridView:(AQGridView *)gridView didDeselectItemAtIndex:(NSUInteger)index 
{ 
    NSString *fileName = [self.fileNames objectAtIndex:index]; 
    //do stuff 
} 
+0

整个项目实际上是围绕例如基于。我想要更多的页面类型的外观和感觉,所以我扩大了单元格。真正让我去做的一件事是,如何无法存储和回调NSString,如应用程序用于运行的UITableView。总之,感谢您的建议,我今晚正在做调试工作,如果我有积极的结果,我会尽快回复您。 – CodaFi

+0

啊!第二个NSArray,这实际上是我的小脑袋放屁就在你发布之前。同样,如果整个事情都有积极的结果,就会发布。 – CodaFi

+0

如果你喜欢一个数组,你可以编写一个简单的对象,保存名称和图标,并将这些对象放在单个数组中。 – vikingosegundo