Other textfield got affected when reload or scrolled


#1

in my   - (void)shinobiDataGrid:(ShinobiDataGrid *)grid prepareCellForDisplay:(SDataGridCell *)cell i set some textfield  column to have a border background but when i call the shinobi reload or scrolled some other textfield column got affected.

if ([cell.coordinate.column.title isEqualToString:@"Equipment ID"]) {
            textCell.textField.text=[NSString stringWithFormat:@"%@", delequipment.EquipmentID];
            
        }
        
        if ([cell.coordinate.column.title isEqualToString:@"Equipment Name"]) {
            textCell.textField.text=delequipment.EquipmentName;
            
        }
        
        if ([cell.coordinate.column.title isEqualToString:@"Drop Off"] && ! (cell.coordinate.row.rowIndex==summaryLineIndex)) {
            
            textCell.textField.text=delequipment.DropOffs;
            textCell.textField.borderStyle=UITextBorderStyleRoundedRect;
            
                   
            
        }

#2

Greetings Program!

At the begining of the prepareCellForDisplay set the borderStyle to none for the textfield in the cell before checking the column titles to set the cell.

Wg


#3

Wizgod,

thank you for the solution i have one last issue any idea how can i save back the changes i made from shinobigrid to my data source. im grabbing my files from  a json file generated from the server. please help me.

attached is three part of my code:

//
// ProductGroupDataSource.m
// TMS
//
// Created by Ariel Marlon Javier on 11/13/13.
// Copyright (c) 2013 Procuro. All rights reserved.
//

#import "ProductGroupDataSource.h"
#import "ProductGroup.h"
#import "OrderDetailProduct.h"
#import "DelEquipment.h"
@implementation ProductGroupDataSource

+(NSArray *)getEquipmentInfo :(NSMutableDictionary *)deliveryInfo
{
    NSDictionary* jsonStopEquipmenttInfo =[deliveryInfo objectForKey:@"DeliveryEquipmentInfo"];
    NSArray* jsonStopEquipmentArray = (NSArray*)[jsonStopEquipmenttInfo objectForKey:@"EquipmentDetails"];
    
    NSMutableArray* equipments = [[NSMutableArray alloc] init];
    for (NSDictionary* jsonEquipment in jsonStopEquipmentArray)
    {
        DelEquipment *delEquipment=[[DelEquipment alloc]init];
        delEquipment.EquipmentID=[jsonEquipment objectForKey:@"EquipmentID"];
        delEquipment.EquipmentName=[jsonEquipment objectForKey:@"EquipmentName"];
        delEquipment.DropOffs=[jsonEquipment objectForKey:@"DropOffs"];
        delEquipment.Net=[jsonEquipment objectForKey:@"Net"];
        delEquipment.PickUp=[jsonEquipment objectForKey:@"PickUp"];
        
        
        NSLog(@"dictionary %@", delEquipment);
        [equipments addObject:delEquipment];
        
        
    }

    return equipments;

}
@end

//
// DelEquipment.m
// TMS
//
// Created by Ariel Marlon Javier on 11/17/13.
// Copyright (c) 2013 Procuro. All rights reserved.
//

#import "DelEquipment.h"

@implementation DelEquipment
-(id)initWithTempValue:(NSString *)ename equipmentID:(NSString *)eID dropOff:(NSString *)d pickUp:(NSString *)p net:(NSString*)n;
{
    if(self==[super init]) {
        self.EquipmentName=ename;
        self.EquipmentID=eID;
        self.DropOffs=d;
        self.PickUp=p;
        self.Net=n;
    }
    
    
    return self;
}
@end



//
    // DelEquipments.m
    // TMS
    //
    // Created by Ariel Marlon Javier on 11/17/13.
    // Copyright (c) 2013 Procuro. All rights reserved.
    //

    #import "DelEquipments.h"
    #import "ProductGroupDataSource.h"
    #import "DelEquipment.h"
    #import "GlobalObjects.h"

    @interface DelEquipments ()

    @end

    @implementation DelEquipments

    NSArray *_data;
    NSMutableArray *_sortedData;
    @synthesize keypad;

    CGRect _realBounds;
    NSInteger summaryLineIndex;
    NSInteger rowIndicator;
    NSInteger rowSelected;
    NSInteger rowSelectedPickUp;
     SDataGridCoord *_editingCell;

    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
            // Custom initialization
        }
        return self;
    }
    -(void)addSummaryLine
    {
        
       
         DelEquipment *delequipment=[[DelEquipment alloc]initWithTempValue:@"" equipmentID:@"" dropOff:@"" pickUp:@"" net:@""];
        [_sortedData addObject:delequipment];
        summaryLineIndex=[globArrayEquipmentTypes count];
        [_shinobiDataGrid reload];
        // }
    }
    - (void)viewDidLoad
    {
        
        [super viewDidLoad];
        _realBounds = self.view.bounds;
        [self renderDeliveryEquipment];
        rowIndicator=0;
        rowSelected=0;
        rowSelectedPickUp=0;
        
        // Do any additional setup after loading the view.
    }
    -(void)renderDeliveryEquipment
    {
        _shinobiDataGrid=[[ShinobiDataGrid alloc]initWithFrame:CGRectMake(20, 130, 700, 270)];
        
        SDataGridTheme *verticalLinesTheme =[SDataGridiOS7Theme new];
        
        
        verticalLinesTheme.hideVerticalGridlines = NO;
        [_shinobiDataGrid applyTheme:verticalLinesTheme];
        
        
        UIFont *font = [UIFont fontWithName:@"Helvetica" size:16.0f];
        UIFont *fontHeader = [UIFont fontWithName:@"Helvetica-Bold" size:20.0f];
        
        // Set the padding for the cell.
        UIEdgeInsets padding = UIEdgeInsetsMake(5, 5, 5, 5);
         _shinobiDataGrid.singleTapEventMask = SDataGridEventEdit;
       
        //create cell style for input
        
        
        // Create an alternating row style.
        SDataGridCellStyle* alternatingRowStyle = [[SDataGridCellStyle alloc] init];
        alternatingRowStyle.font = font;
        alternatingRowStyle.contentInset = padding;
        alternatingRowStyle.backgroundColor = [UIColor colorWithWhite:0.9f alpha:1.0f];
        
        // Create the selected row style.
        SDataGridCellStyle* selectedRowStyle = [[SDataGridCellStyle alloc] init];
        selectedRowStyle.font = font;
        
        selectedRowStyle.contentInset = padding;
        selectedRowStyle.backgroundColor = [UIColor orangeColor];
        selectedRowStyle.textColor = [UIColor whiteColor];
        
        // Create the header style.
        // Style the headers to have a dark background, and white text.
        SDataGridCellStyle* headerStyle = [[SDataGridCellStyle alloc] init];
        headerStyle.font = fontHeader;
        headerStyle.contentInset = padding;
        headerStyle.backgroundColor = [UIColor colorWithWhite:0.6f alpha:1.0f];
        headerStyle.textColor = [UIColor whiteColor];
        
        //[deliveryEquipment.layer setCornerRadius:10.f]
        [_shinobiDataGrid.layer setCornerRadius:4.f];
        // Set the row heights.
        _shinobiDataGrid.defaultHeaderRowHeight = @47;
        _shinobiDataGrid.defaultRowHeight = @37;
        
        // Set the cell styles.
        _shinobiDataGrid.defaultCellStyleForHeaderRow = headerStyle;
        _shinobiDataGrid.defaultCellStyleForSelectedRows = selectedRowStyle;
        _shinobiDataGrid.defaultCellStyleForAlternateRows = alternatingRowStyle;
        
        // Create the style for the cell.
        SDataGridCellStyle* cellStyle;
 
        // Create the columns.
        SDataGridColumn* column;
        column = [[SDataGridColumn alloc] initWithTitle:@"Equipment ID"];
        column.editable = NO;
        column.width = @145;
        column.headerCellStyle.contentInset = padding;
        column.headerCellStyle.textAlignment = NSTextAlignmentCenter;
        
        cellStyle = [[SDataGridCellStyle alloc] init];
        cellStyle.font = font;
        cellStyle.contentInset = padding;
        cellStyle.textAlignment = NSTextAlignmentCenter;
        column.cellStyle = cellStyle;
        
        [_shinobiDataGrid addColumn:column];
        
        column = [[SDataGridColumn alloc] initWithTitle:@"Equipment Name"];
        column.editable = NO;
        column.width = @220;
        column.headerCellStyle.contentInset = padding;
        column.headerCellStyle.textAlignment = NSTextAlignmentCenter;
        
        cellStyle = [[SDataGridCellStyle alloc] init];
        cellStyle.font = font;
        cellStyle.contentInset = padding;
        cellStyle.textAlignment = NSTextAlignmentCenter;
        column.cellStyle = cellStyle;
        
        [_shinobiDataGrid addColumn:column];
        
        // *************************************
        // Uom column
        // *************************************
        column = [[SDataGridColumn alloc] initWithTitle:@"Drop Off"];
          //forenameColumn.sortMode = SDataGridColumnSortModeTriState;
        
        column.sortMode=SDataGridColumnSortModeTriState;
        column.editable = YES;
        column.width = @110;
        column.headerCellStyle.contentInset = padding;
        column.headerCellStyle.textAlignment = NSTextAlignmentCenter;
        
        cellStyle = [[SDataGridCellStyle alloc] init];
        cellStyle.font = font;
        cellStyle.contentInset = padding;
        cellStyle.textAlignment = NSTextAlignmentLeft;
        column.cellStyle = cellStyle;
        [_shinobiDataGrid addColumn:column];
        
        column = [[SDataGridColumn alloc] initWithTitle:@"Pick Up"];
        column.editable = YES;
        column.width = @110;
        column.headerCellStyle.contentInset = padding;
        column.headerCellStyle.textAlignment = NSTextAlignmentCenter;
        
        cellStyle = [[SDataGridCellStyle alloc] init];
        cellStyle.font = font;
        cellStyle.contentInset = padding;
        cellStyle.textAlignment = NSTextAlignmentLeft;
        column.cellStyle = cellStyle;
        [_shinobiDataGrid addColumn:column];
        
        column = [[SDataGridColumn alloc] initWithTitle:@"Net"];
        column.editable = NO;
        column.width = @110;
        column.headerCellStyle.contentInset = padding;
        column.headerCellStyle.textAlignment = NSTextAlignmentCenter;
        
        cellStyle = [[SDataGridCellStyle alloc] init];
        cellStyle.font = font;
        cellStyle.contentInset = padding;
        cellStyle.textAlignment = NSTextAlignmentLeft;
        column.cellStyle = cellStyle;
        [_shinobiDataGrid addColumn:column];
        
        _shinobiDataGrid.dataSource = self;
        _shinobiDataGrid.delegate = self;
        
        
        _data=[ProductGroupDataSource getEquipmentInfo:globDeliveryDictionary];
        
        _sortedData=[NSMutableArray arrayWithArray:_data];
        //_sortedData=[NSArray arrayWithArray:_data];
        [self addSummaryLine];
        [self.view addSubview:_shinobiDataGrid];
    }
    -(NSUInteger)shinobiDataGrid:(ShinobiDataGrid *)grid numberOfRowsInSection:(int)sectionIndex
    {
        return _sortedData.count;
    }
    - (void)shinobiDataGrid:(ShinobiDataGrid *)grid didReorderRow:(SDataGridRow *)rowSwitched withRow:(SDataGridRow *)rowSwitchedWith
    {
        // clone the sorted data into a mutable array
        NSMutableArray* sortedData = [[NSMutableArray alloc] initWithArray:_sortedData];
        
        // perform the switch
        [sortedData exchangeObjectAtIndex:rowSwitched.rowIndex withObjectAtIndex:rowSwitchedWith.rowIndex];
        
        // copy back to the sorted data property
        _sortedData = [[NSMutableArray alloc] initWithArray:sortedData];
    }
    - (void)shinobiDataGrid:(ShinobiDataGrid *)grid prepareCellForDisplay:(SDataGridCell *)cell
    {
        // both columns use a SDataGridTextCell, so we are safe to perform this cast
        SDataGridTextCell* textCell = (SDataGridTextCell*)cell;
        
        // locate the stock
        DelEquipment *delequipment=_sortedData[cell.coordinate.row.rowIndex];
        textCell.textField.text=@"";
       // NSLog(@"delequipment %@" , delequipment.EquipmentID);
        textCell.textField.borderStyle=UITextBorderStyleNone;
        
          if ([cell.coordinate.column.title isEqualToString:@"Equipment ID"]) {
            textCell.textField.text=[NSString stringWithFormat:@"%@", delequipment.EquipmentID];
            
        }
        
        if ([cell.coordinate.column.title isEqualToString:@"Equipment Name"]) {
            textCell.textField.text=delequipment.EquipmentName;
            
        }
        
        if ([cell.coordinate.column.title isEqualToString:@"Drop Off"] && ! (cell.coordinate.row.rowIndex==summaryLineIndex)) {
            
            textCell.textField.text=delequipment.DropOffs;
            textCell.textField.borderStyle=UITextBorderStyleRoundedRect;
            
                   
            
        }
        if ([cell.coordinate.column.title isEqualToString:@"Pick Up"] && ! (cell.coordinate.row.rowIndex==summaryLineIndex)) {
            
            textCell.textField.text=delequipment.PickUp;
             textCell.textField.borderStyle=UITextBorderStyleRoundedRect;
        }
        if ([cell.coordinate.column.title isEqualToString:@"Net"]&& ! (cell.coordinate.row.rowIndex==summaryLineIndex)) {
            
            NSInteger pickup=[delequipment.PickUp integerValue];
            NSInteger dropoff=[delequipment.DropOffs integerValue];
            NSInteger net=pickup+dropoff;
            
            textCell.textField.text=[NSString stringWithFormat:@"%d", net];
            textCell.textField.textAlignment=UITextAlignmentRight;
            
        }
        
        if ([cell.coordinate.column.title isEqualToString:@"Equipment ID"]&& cell.coordinate.row.rowIndex==summaryLineIndex) {
            
            textCell.textField.text=@"SUMMARY";
            UIFont *font = [UIFont fontWithName:@"Helvetica-Bold" size:20.0f];
            textCell.textField.font=font;
            textCell.textField.enabled=NO;
            textCell.textField.userInteractionEnabled=NO;
            
        }
        
        
        if ([cell.coordinate.column.title isEqualToString:@"Drop Off"] && (cell.coordinate.row.rowIndex==summaryLineIndex)) {
            
            
            UIFont *font = [UIFont fontWithName:@"Helvetica-Bold" size:20.0f];
            textCell.textField.font=font;
            textCell.textField.enabled=NO;
            textCell.textField.userInteractionEnabled=NO;
            NSInteger totalDOff=0;
            for (int x=0; x<[_sortedData count]; x++) {
                totalDOff=totalDOff+[[[_sortedData objectAtIndex:x]valueForKey:@"DropOffs"]integerValue];
            }
            textCell.textField.text=[NSString stringWithFormat:@"%d",totalDOff];
            
        }
        if ([cell.coordinate.column.title isEqualToString:@"Pick Up"] && (cell.coordinate.row.rowIndex==summaryLineIndex)) {
            
            
            UIFont *font = [UIFont fontWithName:@"Helvetica-Bold" size:20.0f];
            textCell.textField.font=font;
            textCell.textField.enabled=NO;
            textCell.textField.userInteractionEnabled=NO;
            NSInteger totalDOff=0;
            for (int x=0; x<[_sortedData count]; x++) {
                totalDOff=totalDOff+[[[_sortedData objectAtIndex:x]valueForKey:@"PickUp"]integerValue];
            }
            textCell.textField.text=[NSString stringWithFormat:@"%d",totalDOff];
            
        }
        if ([cell.coordinate.column.title isEqualToString:@"Net"] && (cell.coordinate.row.rowIndex==summaryLineIndex)) {
            
            
            UIFont *font = [UIFont fontWithName:@"Helvetica-Bold" size:20.0f];
            textCell.textField.font=font;
            textCell.textField.enabled=NO;
            textCell.textField.userInteractionEnabled=NO;
            NSInteger totalDOff=0;
            for (int x=0; x<summaryLineIndex; x++) {
                
               
             totalDOff=totalDOff+[[[_sortedData objectAtIndex:x]valueForKey:@"Net"]integerValue];
                            }
            
       
            textCell.textField.text=[NSString stringWithFormat:@"%d",totalDOff];
           // textCell.textField.text=[NSString stringWithFormat:@"%d",67];

      
        }

        
        
    }




    - (BOOL)shinobiDataGrid:(ShinobiDataGrid *)grid shouldBeginEditingCellAtCoordinate:(const SDataGridCoord *)coordinate {
        
        _editingCell=nil;
        _editingCell = (SDataGridCoord *)coordinate;
        
        // Get the cell that was tapped.
        SDataGridCell *cell = (SDataGridCell*)[grid visibleCellAtCoordinate:_editingCell];
       
        
        // Get the frame of the tapped cell
        // CGRect cellFrame = cell.frame;
        if ([_editingCell.column.title isEqualToString:@"Drop Off"]) {
            if (self.pop) {
                [self.pop dismissPopoverAnimated:YES];
            }
             cell.backgroundColor=[UIColor lightGrayColor];
            UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
            Keypad *controller = [storyBoard instantiateViewControllerWithIdentifier:@"Keypad"];
            controller.delegate=self;
            UIPopoverController* popover = [[UIPopoverController alloc] initWithContentViewController:controller];
            popover.delegate = self;
            popover.popoverContentSize = CGSizeMake(250,300);
            
            self.pop=popover;
            
            [popover presentPopoverFromRect:cell.bounds inView:cell permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
            
            
        }
         
        if ([_editingCell.column.title isEqualToString:@"Pick Up"]) {
            if (self.pop) {
                [self.pop dismissPopoverAnimated:YES];
            }
             cell.backgroundColor=[UIColor lightGrayColor];
            UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
            Keypad *controller = [storyBoard instantiateViewControllerWithIdentifier:@"Keypad"];
            controller.delegate=self;
            UIPopoverController* popover = [[UIPopoverController alloc] initWithContentViewController:controller];
            popover.delegate = self;
            popover.popoverContentSize = CGSizeMake(250,300);
            
            self.pop=popover;
            
            [popover presentPopoverFromRect:cell.bounds inView:cell permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
            
            
        }
        
        
        return NO;
        
    }



-(void)dismissKeypad:(NSString *)value
{
    
    
    // Get the cell that we were editing.
    SDataGridTextCell *cell = (SDataGridTextCell*)[_shinobiDataGrid visibleCellAtCoordinate:_editingCell];
    
    NSString *newRecievedValue = cell.textField.text;
    // Find its contents
   //_editingCell = (SDataGridCoord *)coordinate;
    
    // locate the stock
    DelEquipment *delequipment=_sortedData[cell.coordinate.row.rowIndex];
    
// [_orderedData setObject:@(newRecievedValue) atIndexedSubscript:coordinate.row.rowIndex];

 
    
    if ([_editingCell.column.title isEqualToString:@"Drop Off"]) {
         cell.textField.text=value;
        delequipment.DropOffs=value;
        // [_sortedData setObject:newRecievedValue atIndexedSubscript:_editingCell.row.rowIndex];
        //[_data setObject:newRecievedValue atIndexedSubscript:_editingCell.row.rowIndex];
        //[_sortedData se]
      // [_shinobiDataGrid reload];
    }
    
    if ([_editingCell.column.title isEqualToString:@"Pick Up"]) {
        cell.textField.text=value;
       delequipment.PickUp=value;
        //_sortedData setObject:newRecievedValue atIndexedSubscript:_editingCell.row.rowIndex];
               }
    NSInteger drop=[delequipment.DropOffs integerValue];
    NSInteger pick=[delequipment.PickUp integerValue];
    NSInteger net=drop+pick;
    delequipment.Net=[NSString stringWithFormat:@"%d", net];
    [_shinobiDataGrid reload];

    cell.backgroundColor=[UIColor clearColor];
    
    _editingCell = nil;
    [self.pop dismissPopoverAnimated:YES];
}



    -(void)viewWillAppear:(BOOL)animated
    {
        self.view.superview.bounds = _realBounds;
    }

    -(IBAction)btnClose:(id)sender
    {
        
        
        [self dismissViewControllerAnimated:YES completion:nil];
        
    }

-(IBAction)btnSave:(id)sender
{
    
// _data=[ProductGroupDataSource getEquipmentInfo:globDeliveryDictionary];
//    
// _sortedData=[NSMutableArray arrayWithArray:_data];
// //_sortedData=[NSArray arrayWithArray:_data];
//
//
     
    NSLog(@"value of delivery equipment %@", globDeliveryDictionary);
}
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }

    @end

#4

In my app I use Core Data but for a dictionary, I would store the modified rows in another array then maybe iterate through them and grab the object from the datasource with NSPredicate and set the object that way.

I don’t know if this is the best way and I haven’t tested it but it might be a start to something that will work:

-(IBAction)btnSave:(id)sender
{
    // _modifiedEquipment contains edited rows only.
    for (DelEquipment *equipment in _modifiedEquipment)
    {
		// Grab the equipment details object.
		NSPredicate *predicate = [NSPredicate predicateWithFormat:@"EquipmentID == %@", equipment.EquipmentID];
		NSMutableDictionary *equipmentDetails = [[[[globDeliveryDictionary objectForKey:@"DeliveryEquipmentInfo"] objectForKey:@"EquipmentDetails"] filteredArrayUsingPredicate:predicate] objectAtIndex:0];
		
		// Update the equipment details object.
		[equipmentDetails setValue:equipment.DropOffs forKey:@"DropOffs"];
		[equipmentDetails setValue:equipment.Net forKey:@"Net"];
		[equipmentDetails setValue:equipment.PickUp forKey:@"PickUp"];
	}
	
	NSLog(@"value of delivery equipment %@", globDeliveryDictionary);
}

Wg


#5

I encountered a bug, how do pupulate the _modifiedEquipment 

-[__NSDictionaryM EquipmentID]: unrecognized selector sent to instance 0xb195140
2013-12-19 13:05:49.824 TMS[1174:5e0f] <RestConnection.m:connectionDidFinishLoading::300> Request completed
2013-12-19 13:05:49.825 TMS[1174:5e0f] <RestConnection.m:connectionDidFinishLoading::400> its an array!
2013-12-19 13:05:49.838 TMS[1174:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryM EquipmentID]: unrecognized selector sent to instance 0xb195140'
*** First throw call stack:
(0x315d012 0x2abce7e 0x31e84bd 0x314cbbc 0x314c94e 0x361749 0x2ad0705 0x1a042c0 0x1a04258 0x1ac5021 0x1ac557f 0x1ac46e8 0x1a33cef 0x1a33f02 0x1a11d4a 0x1a03698 0x3959df9 0x3959ad0 0x30d2bf5 0x30d2962 0x3103bb6 0x3102f44 0x3102e1b 0x39587e3 0x3958668 0x1a00ffc 0x2eabd 0x2df5 0x1)
libc++abi.dylib: terminate called throwing an exception<br><br>




-(void)dismissKeypad:(NSString *)value
{
    
    
    SDataGridTextCell *cell = (SDataGridTextCell*)[_shinobiDataGrid visibleCellAtCoordinate:_editingCell];
    
    DelEquipment *delequipment=_sortedData[cell.coordinate.row.rowIndex];
    NSString *strDropOff;
    NSString *strPickUp;
    
    
    if ([_editingCell.column.title isEqualToString:@"Drop Off"]) {
        cell.textField.text=value;
        delequipment.DropOffs=value;
        strDropOff=value;
        
    }
    
    if ([_editingCell.column.title isEqualToString:@"Pick Up"]) {
        cell.textField.text=value;
        delequipment.PickUp=value;
        strPickUp=value;
        
    }
    
    
    NSInteger drop=[delequipment.DropOffs integerValue];
    NSInteger pick=[delequipment.PickUp integerValue];
    NSInteger net=drop+pick;
    delequipment.Net=[NSString stringWithFormat:@"%d", net];
    
    NSMutableDictionary *editedEquipment =[[NSMutableDictionary alloc]init];
    [editedEquipment setObject:delequipment.EquipmentID forKey:@"EquipmentID"];
    [editedEquipment setObject:delequipment.EquipmentName forKey:@"EquipmentName"];
    [editedEquipment setObject:delequipment.DropOffs forKey:@"DropOffs"];
    [editedEquipment setObject:delequipment.PickUp forKey:@"PickUp"];
    [editedEquipment setObject:delequipment.Net forKey:@"Net"];
    [_modifiedEquipment addObject:editedEquipment];
    
    
    [_shinobiDataGrid reload];
    
    cell.backgroundColor=[UIColor clearColor];
    
    _editingCell = nil;
    [self.pop dismissPopoverAnimated:YES];
}

#6

Try this instead:

NSInteger drop=[delequipment.DropOffs integerValue];
NSInteger pick=[delequipment.PickUp integerValue];
NSInteger net=drop+pick;
delequipment.Net=[NSString stringWithFormat:@"%d", net];
    
[_modifiedEquipment setObject:delequipment forKey:delequipment.EquipmentId];

Wg


#7

Thank you WG, sorry if i confused you again but actually i got an error saving the modifiedequipment in btnSave, i think  it is in the NSPredicate statement.

-(IBAction)btnSave:(id)sender
{
    // _modifiedEquipment contains edited rows only.
    for (DelEquipment *equipment in _modifiedEquipment)
    {
		// Grab the equipment details object.
		NSPredicate *predicate = [NSPredicate predicateWithFormat:@"EquipmentID = %@", equipment.EquipmentID];
		NSMutableDictionary *equipmentDetails = [[[[globDeliveryDictionary objectForKey:@"DeliveryEquipmentInfo"] objectForKey:@"EquipmentDetails"] filteredArrayUsingPredicate:predicate] objectAtIndex:0];
		
		// Update the equipment details object.
		[equipmentDetails setValue:equipment.DropOffs forKey:@"DropOffs"];
		[equipmentDetails setValue:equipment.Net forKey:@"Net"];
		[equipmentDetails setValue:equipment.PickUp forKey:@"PickUp"];
	}
	
	NSLog(@"value of delivery equipment %@", globDeliveryDictionary);
}

#8

Sorry, my typo, should have been == in the predicate.

Wg


#9

I’m still newbie with NSPredicate it still have an error even if I change to == :(.

thanks,

ariel

for (DelEquipment *equipment in _modifiedEquipment)

    {

        // Grab the equipment details object.

        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"EquipmentID == %@", equipment.EquipmentID];

        NSLog(@"predicate %@",predicate);

        NSMutableDictionary *equipmentDetails = [[[[globDeliveryDictionary objectForKey:@"DeliveryEquipmentInfo"] objectForKey:@"EquipmentDetails"] filteredArrayUsingPredicate:predicate] objectAtIndex:0];

        

        // Update the equipment details object.

        //[equipmentDetails setValue:equipment.EquipmentID forKey:@"DropOffs"];

        [equipmentDetails setValue:equipment.DropOffs forKey:@"DropOffs"];

        [equipmentDetails setValue:equipment.Net forKey:@"Net"];

        [equipmentDetails setValue:equipment.PickUp forKey:@"PickUp"];

    }

#10

this is the error i encountered :

[__NSDictionaryM EquipmentID]: unrecognized selector sent to instance 0x15d2c8e0

2013-12-22 14:04:40.281 TMS[15837:907] *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: '-[__NSDictionaryM EquipmentID]: unrecognized selector sent to instance 0x15d2c8e0’

*** First throw call stack:

(0x315f012 0x2abee7e 0x31ea4bd 0x314ebbc 0x314e94e 0x361aa9 0x2ad2705 0x1a062c0 0x1a06258 0x1ac7021 0x1ac757f 0x1ac66e8 0x1a35cef 0x1a35f02 0x1a13d4a 0x1a05698 0x395bdf9 0x395bad0 0x30d4bf5 0x30d4962 0x3105bb6 0x3104f44 0x3104e1b 0x395a7e3 0x395a668 0x1a02ffc 0x2e54d 0x2885 0x1)

libc++abi.dylib: terminate called throwing an exception


#11

Comment everything out in the for loop and add an NSLog and see what you get for the equipment objects.

for (DelEquipment *equipment in _modifiedEquipment)
{
     NSLog(@"Equipment object: %@", equipment);
}

Wg


#12

this one works. thank you again for the assistance.

for (DelEquipment *equipment in _modifiedEquipment) {
            
        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"EquipmentID == %@", [equipment valueForKey:@"EquipmentID"]];
           
        NSMutableDictionary *equipmentDetails = [[[[globDeliveryDictionary valueForKey:@"DeliveryEquipmentInfo"] valueForKey:@"EquipmentDetails"] filteredArrayUsingPredicate:predicate] objectAtIndex:0];
                [equipmentDetails setValue:[equipment valueForKey:@"DropOffs"] forKey:@"DropOffs"];
                [equipmentDetails setValue:[equipment valueForKey:@"Net"] forKey:@"Net"];
                [equipmentDetails setValue:[equipment valueForKey:@"PickUp"] forKey:@"PickUp"];

    }