Set a value from the clicked cell by another view controller


#1

I have a cell with UITextField inside that calls a customized numeric keypad, how can i set the value that was in my numeric keypad back to the UITextField

-(void)dismissTempKeypad:(NSString *)value
{
    
    if (_shinobiDataGrid.columns.count>0) {
        if (_shinobiDataGrid.selectedCellCoordinates.count>0) {
            SDataGridCoord *coord=[_shinobiDataGrid.selectedCellCoordinates objectAtIndex:0];
            SDataGridCell *cell=(SDataGridCell *)[_shinobiDataGrid visibleCellAtCoordinate:coord];
            
            NSLog(@"selected cell %@", cell);
            UITextField *txtQuantity=(UITextField *)[cell viewWithTag:103];
            if (![cell.coordinate.column.title isEqualToString:@"Qty Rcvd"]&& txtQuantity !=nil) {
                txtQuantity.text=value;
                 src=nil;
            }
        }
    }
   
   
    [self.pop dismissPopoverAnimated:YES];
    
}
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    
    
    if (self.pop) {
        [self.pop dismissPopoverAnimated:YES];
    }
    UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    TMSTempKeypad *controller = [storyBoard instantiateViewControllerWithIdentifier:@"TMSTempKeypad"];
    controller.delegate=self;
    
    UIPopoverController* popover = [[UIPopoverController alloc] initWithContentViewController:controller];
    popover.delegate = self;
    popover.popoverContentSize = CGSizeMake(250,300);
    
    self.pop=popover;
    [popover presentPopoverFromRect:textField.bounds inView:textField permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    
    return NO;
}

- (void)shinobiDataGrid:(ShinobiDataGrid *)grid prepareCellForDisplay:(SDataGridCell *)cell
{
    // both columns use a SDataGridTextCell, so we are safe to perform this cast
    SDataGridTextCell* textCell = (SDataGridTextCell*)cell;
    OrderGroup *group=_sortedData[cell.coordinate.row.sectionIndex];
    OrderDetailProduct *order=group.groups[cell.coordinate.row.rowIndex];
    
    textCell.textField.text=@"";
    UIButton *btnTemp=(UIButton *)[cell viewWithTag:99];
    if (![cell.coordinate.column.title isEqualToString:@"Temp"] &&btnTemp !=nil) {
        [btnTemp removeFromSuperview];
    }
    
    UITextField*txtTemp=(UITextField *)[cell viewWithTag:100];
    if (![cell.coordinate.column.title isEqualToString:@"Temp"] && txtTemp!=nil) {
        [txtTemp removeFromSuperview];
    }
    
    
    if ([cell.coordinate.column.title isEqualToString:@"Temp"])
    {
        if (btnTemp==nil) {
            btnTemp=[UIButton buttonWithType:UIButtonTypeCustom];
            [btnTemp setImage:btnTempImage forState:UIControlStateNormal];
            btnTemp.tag=99;
            btnTemp.frame=CGRectMake(2, 6, btnTempImage.size.width, btnTempImage.size.height);

            [btnTemp setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin];
            [btnTemp addTarget:self action:@selector(showTemp:) forControlEvents:UIControlEventTouchUpInside];
            
            
            
            [textCell addSubview:btnTemp];
        }
        
        if (txtTemp==nil) {
            txtTemp=[[UITextField alloc]init];
            txtTemp.tag=100;
            txtTemp.text=order.Temp;
            txtTemp.delegate=self;
            txtTemp.borderStyle=UITextBorderStyleRoundedRect;
             txtTemp.frame=CGRectMake(25, 5, 29, 25);
             [txtTemp addTarget:self action:nil forControlEvents:UITextFieldTextDidBeginEditingNotification];
            
            
            
            [textCell addSubview:txtTemp];
        }
        
              
        
    }
}

#2

Greetings Program!

Try this:

Edit Note: objectAtIndex is the 0 start index of the column in the seleted row not the cells in the column of the selected cell like I had it.

-(void)dismissTempKeypad:(NSString *)value 
{
	// Make sure we have a selected row.
	if (shinobiDataGrid.selectedRows.count > 0) {
		// selectedCellCoordinates returns an array of the column cells in the selected row that was tapped.
		// 3 is the index of the 4th column (Temp) that contains the text field.
		SDataGridCoord *coord = [shinobiDataGrid.selectedCellCoordinates objectAtIndex:3];
		SDataGridCell *cell = (SDataGridCell *)[shinobiDataGrid visibleCellAtCoordinate:coord];
		
		UITextField*txtTemp=(UITextField *)[cell viewWithTag:100];
		if (![cell.coordinate.column.title isEqualToString:@"Temp"] && txtTemp!=nil) {
			txtTemp.text = value;
		}
	}

	src=nil;
	[self.pop dismissPopoverAnimated:YES];
}

Wg


#3

no luck  :confused: i nslog the actual cell but i’m not displaying the value 

selected cell SDataGridTextCell: 0x1721aac0; frame = {{0, 250.5}, {63.5, 36}}; coordinate = {c:Location,r:5,s:0}
2013-11-25 12:18:46.858 TMS[577:907] selected cell SDataGridTextCell: 0xb11bd50; frame = {{0, 71}, {63.5, 35.5}}; coordinate = {c:Location,r:0,s:0}


-(void)dismissTempKeypad:(NSString *)value
{
    
    if (_shinobiDataGrid.columns.count>0) {
        if (_shinobiDataGrid.selectedCellCoordinates.count>0) {
            SDataGridCoord *coord=[_shinobiDataGrid.selectedCellCoordinates objectAtIndex:0];
            SDataGridCell *cell=(SDataGridCell *)[_shinobiDataGrid visibleCellAtCoordinate:coord];
            
            NSLog(@"selected cell %@", cell);
            UITextField *txtQuantity=(UITextField *)[cell viewWithTag:103];
            if (![cell.coordinate.column.title isEqualToString:@"Qty Rcvd"]&& txtQuantity !=nil) {
                txtQuantity.text=value;
                 src=nil;
            }
        }
    }
   
   
    [self.pop dismissPopoverAnimated:YES];
    
}

#4

I revised your code to point to the actual column and made some changes with the condition it works but im not comfortable since you place those syntax for a reason hope you can find time to review this. and how can i programmaticaly select a row when for i clicked the uitextfield inside the Qty Recvd column i selected automatically the whole row.

if (_shinobiDataGrid.columns.count>0) {
        if (_shinobiDataGrid.selectedCellCoordinates.count>0) {
            SDataGridCoord *coord=[_shinobiDataGrid.selectedCellCoordinates objectAtIndex:8];
            SDataGridCell *cell=(SDataGridCell *)[_shinobiDataGrid visibleCellAtCoordinate:coord];
            
            NSLog(@"selected cell %@ %@", cell, cell.coordinate.column.title);
            UITextField *txtQuantity=(UITextField *)[cell viewWithTag:103];
            if ([cell.coordinate.column.title isEqualToString:@"Qty Rcvd"]) {
                txtQuantity.text=value;
                 src=nil;
            }
        }
    }
   
   
    [self.pop dismissPopoverAnimated:YES];

#5

I thought that selectedCellCoordinates returned the cells of the selected rows in the column that was tapped.

On second look, selectedCellCoordinates returns an array of the cells in the selected row that was tapped (I’ve updated the comment in the code to note this and replaced the conditions).

Looking at the image of your grid (in this post) you have it correct above when using objectAtIndex:8 to get the 9th column in the grid (Quantity Received).

I would say you’re good to go as long as you don’t change the position of the Quantity Received otherwise you’ll have to update the objectAtIndex :slight_smile:

Wg


#6

now i’m comfortable with my code. thank you again. :slight_smile:


#7

any tips how i will save/update  this back to my json file? :D