samedi 25 avril 2015

Populating ViewBased table from data in 6 different NSMutable arrays


I have 6 different NSMutable arrays [(Arr(A); Arr(B); etc.] each of which represents data for one cell of a row in the table. The array is essentially the key representation. They are built in a prior classes, passed to the current class and have exactly the same number of string objects (63) in each. The table is essential a data representation of

Questions:

  1. Must I build a NSDictionary with 'keys' and 'objects'. How do I build thatDictionary. I have tried various methods stepping through a count loop with no success. I can to find a method for inserting objects for specific keys.

  2. Can I load the table directly from the various arrays without a ViewController. I have the table and id's laid out but I have not been able to add a ViewController to this class - I only have 'Files Owner'. If this is easiest how can I do that.

  3. If needed, how do I take elements of the 6 arrays in order as a comma delimited string in another array that becomes the input to a row of of the table and therefore parsed into the table.

No code to offer because all my attempts w/code have been unsuccessful.

NEED SOME SPECIFIC DIRECTION HERE.

.h

     //  ReportsOutput.h
        //  Stamp Collection
        //  Created by Terry Lengel on 4/20/15.
        //  Copyright (c) 2015 Terry Lengel. All rights reserved.

        #import <Cocoa/Cocoa.h>
        #import <Foundation/Foundation.h>
        #import "ReportsClass.h"

        @interface ReportsOutput : NSWindowController <NSMenuDelegate,NSTableViewDataSource,NSTableViewDelegate,NSApplicationDelegate>{


        // variable and outlet for the table

            IBOutlet NSTableView *rptTable;

        }

        // data element sources

        @property(nonatomic,strong) NSMutableArray *tblYrScott;
        @property(nonatomic,strong) NSMutableArray *tblYrExt;
        @property(nonatomic,strong) NSMutableArray *tblYrYear;
        @property(nonatomic,strong) NSMutableArray *tblYrType;
        @property(nonatomic,strong) NSMutableArray *tblYrPrice;
        @property(nonatomic,strong) NSMutableArray *tblYrDescription;

        // the Display data source array for the table

        @property(strong) NSMutableArray *rptData;

        #pragma mark - Method Declarations

        -(BOOL)conditionData;

        -(NSDictionary *)makeDictionaryRecord:(NSString*)scott withInfo:(NSString*)ext withInfo:(NSString*)year withInfo:(NSString*)type withInfo:(NSString*)price withInfo:(NSString*)Description;

        @end

    .m

        //  ReportsOutput.m
        //  Stamp Collection
        //  Created by Terry Lengel on 4/20/15.
        //  Copyright (c) 2015 Terry Lengel. All rights reserved.

        #import "ReportsOutput.h"
        #import "ReportsClass.h"

        @interface ReportsOutput ()

        @end

        @implementation ReportsOutput

        @synthesize tblYrScott;
        @synthesize tblYrExt;
        @synthesize tblYrType;
        @synthesize tblYrPrice;
        @synthesize tblYrYear;
        @synthesize tblYrDescription;

        @synthesize rptData;

        -(id)initWithWindow:(NSWindow *)window{
            self = [super initWithWindow:window];
            if (self){
                // initialize code here
            }
            return self;

        }


        -(void)windowDidLoad {
            [super windowDidLoad];

            // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
        }

        -(void)applicationDidFinishLaunching:(NSNotification *)notification{

            //Insert code here to initialize your application
        }

        //  Terminate the app by using the RED button:

        -(BOOL)applicationShouldTerminateAfterLastWindowClosed:
        (NSApplication *)sender{

            return YES;

        }

        -(void)awakeFromNib{

            if (self.conditionData == YES){

                [rptTable reloadData];
            }

        }

        -(BOOL)windowShouldClose:(id)sender{
            return YES;
        }

        -(void)performClose:(id)sender{
            [self close];
        }

        #pragma mark - Table View Data Source

        -(NSInteger)numberOfRowsInTableView:(NSTableView *)tableView{

            return rptData.count;

        }

        -(NSView *) tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row{

            NSTableCellView *scott = [tableView makeViewWithIdentifier:@"Scott" owner:self];

            scott.textField.stringValue = [self.rptData objectAtIndex:row];

            return scott;


        }

        // request for sorting

        -(void) tableView:(NSTableView *)tableView sortDescriptorsDidChange:(NSArray *)oldDescriptors{

            // table view received sort request
            //sort the data, then reload the tableView data:

            [rptData sortUsingDescriptors:[rptTable sortDescriptors]];

            [rptTable reloadData];

        }

        -(BOOL)conditionData{

            BOOL conditionData = NO;

            NSString *rPrice;
            NSString *rExt;
            NSString *rYear;
            NSString *rType;
            NSString *rDescription;


            for (int b=0; b<[tblYrScott count]; ++b){

                //condition source data to remove any null appearences

                rExt = [tblYrExt objectAtIndex:b];
                if (rExt == (id)[NSNull null] || rExt.length == 0 ){
                    rExt = @"None";
                }else if ([rExt isEqualToString:@" "]){
                    rExt = @"None";
                }else
                    rExt = [tblYrExt objectAtIndex:b];

                rYear = [tblYrYear objectAtIndex:b];
                if (rYear == (id)[NSNull null] || rYear.length == 0 ){
                    rYear = @" ";
                }else
                    rYear = [tblYrYear objectAtIndex:b];

                rType = [tblYrType objectAtIndex:b];
                if (rType == (id)[NSNull null] || rType.length == 0 ){
                    rType = @" ";
                }else
                    rType = [tblYrType objectAtIndex:b];

                rPrice = [tblYrPrice objectAtIndex:b];
                if (rPrice == (id)[NSNull null] || rPrice.length == 0 ){
                    rPrice = @"n/r";
                }else
                    rPrice = [tblYrPrice objectAtIndex:b];

                rDescription = [tblYrDescription objectAtIndex:b];
                if (rDescription == (id)[NSNull null] || rDescription.length == 0 ){
                    rDescription = @" ";
                }else
                    rDescription = [tblYrDescription objectAtIndex:b];

                NSDictionary *rptData = @{@"Scott":[tblYrScott objectAtIndex:b],@"Ext":rExt,@"Year":rYear,@"Type":rType,@"Price":rPrice,@"Description":rDescription};

            }

            //[rptTable reloadData];

            return conditionData = YES;
        }


        -(NSDictionary*) makeDictionaryRecord:(NSString *)scott withInfo: (NSString *)ext withInfo: (NSString *)year withInfo: (NSString *)type withInfo: (NSString *)price withInfo: (NSString *)description{

            NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:scott,@"Scott",ext,@"Ext",year,@"Year",type,@"Type",price,@"Price",description,@"Description", nil];

           return dict;

        }

        @end

Data Sample:

2015-04-25 12:20:49.251 StampsProjectDev[2981:591183]  rptData = {
    Description = "Lunar New Year - Horse";
    Ext = None;
    Price = "n/r";
    Scott = 4846;
    Type = C;
    Year = 2014;
}
2015-04-25 12:20:49.252 StampsProjectDev[2981:591183]  rptData = {
    Description = "Jimi Hendrix";
    Ext = None;
    Price = "n/r";
    Scott = 4880;
    Type = C;
    Year = 2014;
}
2015-04-25 12:20:49.252 StampsProjectDev[2981:591183]  rptData = {
    Description = "Charlton Heston";
    Ext = None;
    Price = "n/r";
    Scott = 4892;
    Type = C;
    Year = 2014;
}
2015-04-25 12:20:49.252 StampsProjectDev[2981:591183]  rptData = {
    Description = "Janice Joplin";
    Ext = None;
    Price = "n/r";
    Scott = 4916;
    Type = C;
    Year = 2014;
}
2015-04-25 12:20:49.252 StampsProjectDev[2981:591183]  rptData = {
    Description = "Ralph Ellison";
    Ext = None;
    Price = "n/r";
    Scott = 4866;
    Type = C;
    Year = 2014;
}


Aucun commentaire:

Enregistrer un commentaire