Search code examples
objective-ccocoa-touchipadaqgridview

NSString In AQGridViewCell


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

Solution

  • 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
    }