SDataGridMultiLineTextCell don't works well


#1

i use the xamarin edition shinobigrid,some column have very long text ,after set celltyle to SDataGridMultiLineTextCell and override the HeightForRow method ,the text shows in multilines,but the end of some text get cut off.one strange thing is after i click some cell the text can display all.it looks like the textlabel padding with the parent uiview(the cell).i try to set the textlabel's frame equal to the textcell's bounds but seems not work.any methond to set the textlabel show all text?


#2

Greetings Program!

I haven’t gotten into the Xamarin side of things but if I edited a multiline cell, I needed to reload the cell after editing for it to populate the entire height:

- (void)shinobiDataGrid:(ShinobiDataGrid *)grid didFinishEditingCellAtCoordinate:(SDataGridCoord *)coordinate
{
    if ([coordinate.column.title isEqualToString:@"Notes"])
    {
		// Find the cell.
    	SDataGridMultiLineTextCell* cell = (SDataGridMultiLineTextCell*)[_shinobiDataGrid visibleCellAtCoordinate:coordinate];
		[_shinobiDataGrid reloadColumns:@[cell]];
	}
}

And in the heightForRowAtIndex, you’ll need to find some way of calculating the height of the text. I found this method on stackoverflow to calculate the height (http://stackoverflow.com/questions/18368567/uitableviewcell-with-uitextview-height-in-ios-7). If you have more than one column of multiline cells, you’d need to go through your datasource for the row and calculate the height for the text in each multiline column and return the largest.

- (CGFloat)textViewHeightForAttributedText: (NSAttributedString*)text andWidth: (CGFloat)width {
    UITextView *calculationView = [[UITextView alloc] init];
    [calculationView setAttributedText:text];
    CGSize size = [calculationView sizeThatFits:CGSizeMake(width, FLT_MAX)];
    return size.height;
}

Wg


#3

wizgod

Greetings Program!

I haven’t gotten into the Xamarin side of things but if I edited a multiline cell, I needed to reload the cell after editing for it to populate the entire height:

- (void)shinobiDataGrid:(ShinobiDataGrid *)grid didFinishEditingCellAtCoordinate:(SDataGridCoord *)coordinate
{
    if ([coordinate.column.title isEqualToString:@"Notes"])
    {
		// Find the cell.
    	SDataGridMultiLineTextCell* cell = (SDataGridMultiLineTextCell*)[_shinobiDataGrid visibleCellAtCoordinate:coordinate];
		[_shinobiDataGrid reloadColumns:@[cell]];
	}
}

And in the heightForRowAtIndex, you’ll need to find some way of calculating the height of the text. I found this method on stackoverflow to calculate the height (http://stackoverflow.com/questions/18368567/uitableviewcell-with-uitextview-height-in-ios-7). If you have more than one column of multiline cells, you’d need to go through your datasource for the row and calculate the height for the text in each multiline column and return the largest.

- (CGFloat)textViewHeightForAttributedText: (NSAttributedString*)text andWidth: (CGFloat)width {
    UITextView *calculationView = [[UITextView alloc] init];
    [calculationView setAttributedText:text];
    CGSize size = [calculationView sizeThatFits:CGSizeMake(width, FLT_MAX)];
    return size.height;
}

Wg

hi,thansk for reply.i am not try to use uitextview,after the grid load the cell is not editable.i think after i click the cell  it will show the in edit mode(uitextview).in the HeightForRow method,i set a height more bigger than the lable but still not work.


#4

Do you have any code you can share so I can get a better understanding of what you are describing?

Wg


#5

wizgod

Do you have any code you can share so I can get a better understanding of what you are describing?

Wg

in short word.  SDataGridMultiLineTextCell textlabel cut off someword even the height is enough ,but when i click the cell it changed to edit mode, the  uitextview  show it well.


#6

I was able to replicate the issue in the HandlingEditing sample app. It looks like the subviews of the SDataGridMultiLineTextCell are not sizing to fit the cell view. In the documentation, it notes this about the SDataGridCell fitSubViewsToView property:

fitSubviewsToView

Setting this property to YES results in any added subviews having dimensions automatically applied so that they are the same size as the cell. Default value is YES for the grid and NO for the data-grid.

I can’t say for certain this is the reason but since the grid does resize the subview to fit after certain events but then returns it to the original size on other events, I think this is probably why it’s happening.

Maybe the ShinobiSquad can provide some insight as to a solution.

Wg


#7

Hi all,

Thank you for raising this, this does look like a bug in the grids framework. I’ve raised an issue in our backlog to fix this. In the meantime, we’ll take a look at a workaround to allow you to carry on working with the existing framework.

The fitSubviewsToView property on cells is applied when the cell is redrawn. This is why you will see the cell label being resized after certain events. The best workaround for the moment may well be to trigger these kind of events after editing a cell, we shall investigate this.

Kind regards,

Dan


#8

Hi all,

Here is a workaround which should allow you to get going with multi line text cells, until we have released the bug fix.

As part of the process involved when a multi line text cell is styled, its label is resized to fit the cell which contains it. So a workaround for this issue would be to re-apply the current style to your cell after you have finished editing its text. You can do this in the shinobiDataGrid:didFinishEditingCellAtCoordinate: method on SDataGridDelegate. In your app, adopt the delegate protocol if you don’t already, then implement this method as follows:

- (void)shinobiDataGrid:(ShinobiDataGrid *)grid didFinishEditingCellAtCoordinate:(SDataGridCoord *)coordinate
{
    // find the cell that was edited
    SDataGridMultiLineTextCell* cell = (SDataGridMultiLineTextCell*)[grid visibleCellAtCoordinate:coordinate];
    
    // Rest of delegate functionality goes here...

    [cell applyStyle:grid.defaultCellStyleForRows];
}

Once the cell is styled, its label will be resized to fit its text, and it will be repositioned in the center of the cell.

I hope this helps, let us know how things go!

Regards,

Dan


#9

Hi Dan,

In the HandlingEditing sample app, I implemented it as such and it didn’t work (I set the heightForRowAtIndex to @300):

// determine which column this cell belongs to
    if ([cell.coordinate.column.title isEqualToString:@"Forename"])
    {
	SDataGridMultiLineTextCell* textCell2 = (SDataGridMultiLineTextCell*)cell;
        updatedText = textCell2.text;
	person.forename = updatedText;
		
	[textCell2 applyStyle:grid.defaultCellStyleForRows];
    }

Wg


#10

Hi wizgod,

Can I quickly check whether you changed the cell type on the column to be SDataGridMultiLineTextCell? To replicate the issue in the sample, I changed all the column cell types to be SDataGridMultiLineTextCell. This means that you also have to update the shinobiDataGrid:prepareCellForDisplay: datasource method. I found that if I did that, and updated all the places where the code was using cell.textField instead of cell.textLabel, I was able to implement the workaround.

If you’ve done that, and you’re still getting the issue, could you let us know?

Regards,

Dan


#11

Hi Dan,

Both were implemented but I am finding that:

  1. depending on where I tap/click on another cell on the device or simulator to get out of edit mode, the workaround does not work.

  2. If I edit multiple times, the workaround has a toggle effect - first edit it works, second edit it reverts back, edit again and it works again and so on (or turns into #3).

  3. Some rows I can go 5 or 6 times with the workaround then it’s back to #1 and #2.

  4. Sometimes the workaround would work after editing it 4 or 5 times and then back to any of the above.

Odd behavior or maybe it’s just me.

Is there any way to applyStyle: after the cell has loaded instead of waiting to edit and have it changed after editing?

Wg


Swift : Auto Text in Shinobi Grid
#12

Dan

Hi wizgod,

Can I quickly check whether you changed the cell type on the column to be SDataGridMultiLineTextCell? To replicate the issue in the sample, I changed all the column cell types to be SDataGridMultiLineTextCell. This means that you also have to update the shinobiDataGrid:prepareCellForDisplay: datasource method. I found that if I did that, and updated all the places where the code was using cell.textField instead of cell.textLabel, I was able to implement the workaround.

If you’ve done that, and you’re still getting the issue, could you let us know?

Regards,

Dan

Hi Dan,i think you miss understand my porblem.the proplem is when the cell show with textlabel  it cutoff the text.but after click the cell show with uitextview works well. but i don’t need the user to click the cell. so if i don’t  override didFinishEditingCellAtCoordinate how to show the text well when  the cell first display.


#13

Hi guys,

I’m afraid we’ve been unable to replicate the behaviour you guys have seen in your projects at this end. Would you be able to send over your projects so we can replicate the issue here? That should allow us to determine what is causing the problem. You can email the projects over to us at info@shinobicontrols.com.

Many thanks,

Dan


#14

Been away Dan; I’ve just sent it.

Wg


#15

Hi Wizgod,

Thank you for sending in your project. We’ve been able to replicate the issue with multi line text cells at our end now. It looks like there is a bug with the current implementation which contrains the text label inside the cell to the wrong frame. We’ve raised a bug in our backlog, and we shall fix this in a future release. In the meantime, a workaround for this issue would be to create a category to patch the text label class which the multi line text cell uses internally. The code for that category is as follows:

First the header:

#import <ShinobiGrids/SGridTextLabel.h>

@interface SGridTextLabel (Fix)

@end

Then the implementation:

#import "SGridTextLabel+Fix.h"

@implementation SGridTextLabel (Fix)

- (void)setFrame:(CGRect)frame {
    CGPoint newCentre;
    
    newCentre.x = CGRectGetMidX(frame);
    newCentre.y = CGRectGetMidY(frame);
    
    [super setCenter:newCentre];
    
    frame.origin = CGPointZero;
    
    if ( self.bounds.size.width != frame.size.width
        || self.bounds.size.height != frame.size.height) {
        [super setBounds:frame];
    }
}

@end

Internally, the multi line text cell uses an instance of SGridTextLabel to display its text. This implementation overrides the current behaviour of the cell, which was constraining its frame to the wrong bounds. When we have fixed the internal implementation of the cell, we shall update this thread to let you know.

sdhjl2000 - The workaround has been provided in Objective-C as the original issue is on the native side, but I’m afraid it doesn’t look like you’ll be able to take the same approach on the Xamarin side. Until we have this bug fixed, possibly the simplest workaround would be to subclass SDataGridCell and create your own implementation which contains a multi line UILabel. Apologies that we haven’t come up with an easier workaround for Xamarin yet - we shall let you know when this bug is addressed.

I hope that helps, let me know how things go. 

Regards,

Dan