Using a Picker/Date Picker or TableVIew to Select Values When Editing


#1

Hi!

As per the subject, am I able to use a picker/datepicker to populate the cell or select a value from a tableview that would pop up when the cell is selected for editing? If so, is there any example on how to do it or perhaps instructions on how I would go about doing it?

Thanks!

Wg


#2

So the answer to my first question is yes.

The Tasks demo in the ShinobiPlay app has all the functionality I am looking for:

  • selecting a column to get a date picker- selecting a column to get a list of values (category column)
  • Add New button that positions under the grid and relocates as rows are deleted or added

Is the code for this Task demo available? Or are there any examples as to how to do this?

Thanks!

Wg


#3

Hi Wizgod,

The date picker itself is a view controller inside of a UIPopoverController that we display when the user double taps on a custom cell.

The “Add New…” button you see in Shinobi play doesn’t really have anything to do with the grid or it’s datasource. All that we do there is update the bottom content inset on the scroll view that the grid is contained in, and add a UIButton as a subview of the grid. 

Unfortunately the code for ShinobiPlay isn’t available to the public, but we do have a lot of blog posts on how to customise our grids and charts available in our blog section of the site.

Hope that helps! 


#4

Thanks! I will try that.

Wg


#5

For the popover I have done it like so:

- (void)shinobiDataGrid:(ShinobiDataGrid *)grid willBeginEditingCellAtCoordinate:(SDataGridCoord *)coordinate
{
    // find the cell that was edited
	SDataGridCell *cell = (SDataGridCell*)[shinobiDataGrid visibleCellAtCoordinate:coordinate];

	if ([cell.coordinate.column.title isEqualToString:@"Part/Service"])
    {
		// The view controller you want to present as popover.
		PriceListViewController *controller = (PriceListViewController *)[[PriceListViewController alloc] init];
		
		UIPopoverController* popover = [[UIPopoverController alloc] initWithContentViewController:controller];
		popover.delegate = self;
		popover.popoverContentSize = CGSizeMake(320,300);
		
		//Present the popover
		[popover presentPopoverFromRect:cell.frame
								  inView:self.view
				permittedArrowDirections:UIPopoverArrowDirectionAny
								animated:YES];
	}
}

#6

Great! Thanks for posting your solution here for everyone to see.


#7

Hey Guys, what if i had to do this with a ShinobiGrid

The method i see closest to get the cell that i click on is  

_ visibleCellAtCol: andRow: _

I know how to get the column, would you know how to get the SGridRow that I clicked on? I'm a bit confused on how to obtain that.

Thanks


#8

nvm got it like this 

    NSArray *visibleRows = [spreadSheet visibleRows];
    SGridRow visibleRow;
     //initialize 
    visibleRow.index = -1;
    visibleRow.section = -1;
    for(int i = 0 ; i < [visibleRows count] ; i++)
    {
        [[visibleRows objectAtIndex:i] getValue:&visibleRow];
        if(gridCoord.rowIndex == visibleRow.index)
            break;
        
    }

SGridCell *gridCell = [spreadSheet visibleCellAtCol:gridCoord.column andRow:visibleRow];

And then i present the popup from the gridCell’s rect.