0

I have an AQGridView set up to display the files in the documents directory along with 4 other documents that are predefined and loaded into the table at startup. I need to know how I can set the cell to hold the URL of the document (yes, even the predefined ones! They are all just NSStrings after all.) so it can be called later with

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

and loaded into a new view with a custom -(id)init method. Right now, an NSLog of a documents directory object cell returns a (NULL), and SIGABRT's in the log.


OK, bounty is up. I assume this means I can demand a little quality. Code snippets would be great!

Code available on request.

EDIT WORKING CODE:

//.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];
        }
CodaFi
  • 43,043
  • 8
  • 107
  • 153

1 Answers1

1

Have a look on the Springboard sample code coming with AQGridView.

And exchange the codes for SpringBoardIconCell and SpringBoardViewController with the codes I put here.

Basically just add a UILabel to the SpringBoardIconCell, add it to the View hierarchy and set the text in the gridView:cellForItemAtIndex: from the dataSource.

and finally:

-(void)gridView:(AQGridView *)gridView didDeselectItemAtIndex:(NSUInteger)index
{
    NSString *fileName = [self.fileNames objectAtIndex:index]; 
    //do stuff
}
Glorfindel
  • 21,988
  • 13
  • 81
  • 109
vikingosegundo
  • 52,040
  • 14
  • 137
  • 178
  • The whole project is actually based around that example. I was going for more of a Pages type look and feel, so I expanded the cells. The one thing that really got me going was how there was no way to store and call back an NSString like the UITableView the app used to run on. In short, thanks for the suggestion, I am doing debug work tonight, and will get back to you shortly if I have positive results. – CodaFi Nov 09 '11 at 02:04
  • Ah! A second NSArray, that was actually my little brain fart just moments before you posted. Again, will post if there are positive outcomes from this whole thing. – CodaFi Nov 09 '11 at 02:06
  • If you prefer one array, you can write a simple object, holding the name and the icon and put this objects in the single array. – vikingosegundo Nov 09 '11 at 02:09
  • Oh, no. This is in no way about simplicity. The double array concept was just a stroke of genius (sorry if this is rudimentary for you or anyone else, I'm (somewhat) new). – CodaFi Nov 09 '11 at 02:14
  • 1
    it is just a matter of taste. Some might argue, that name and icon belong together and should be capsulated in one object with all objects in the same array. I would be fine with two arrays. – vikingosegundo Nov 09 '11 at 02:17
  • Beautiful! +50 is all yours bud! (At least in 21 hours, sorry. Best answer and a +1 will have to do for now) – CodaFi Nov 09 '11 at 02:55