6

I subclassed EntryElement and have set the UILineBreakMode in the GetCell method as such:

public class EntryElementEnhanced : EntryElement, IElementSizing
{
    public EntryElementEnhanced(string caption, string placeholder, string value) : base (caption, placeholder, value) {}


    public float GetHeight(UITableView view, NSIndexPath indexPath)
    {
        return 100.0f; //arbitrary number just for testing
    }

    public override UITableViewCell GetCell (UITableView tv)
    {
        var cell = base.GetCell (tv);
        cell.TextLabel.LineBreakMode = UILineBreakMode.WordWrap;
        cell.TextLabel.Lines = 0;


        return cell;
    }
}

This does not seem to make the text that gets entered into the cell word-wrapped. Should I be setting this somewhere else?

If someone knows a better approach, what I'm trying to accomplish at a higher level is I want to create the equivalent of an UITextArea in MonoTouch.Dialog.

valdetero
  • 4,624
  • 1
  • 31
  • 46

4 Answers4

5

EntryElement creates an UITextField which is a one line only control.

If you need multiple lines then I suggest you to create your own Element, e.g. MultilineEntryElement, and have it use a UITextView internally.

You could do this by copy-pasting code from EntryElement or by inheriting from the UIViewElement (or a bit of both).

Community
  • 1
  • 1
poupou
  • 43,413
  • 6
  • 77
  • 174
  • This seemed to work for me with copying code from the entry element. The only issue that I see now is that in the `GetCell` method from `EntryElement`, `entry.ShouldEndEditing += delegate` tries to reference `root.Sections`. This is an internal list that I can't access in my subclass. Any ideas for a workaround? – valdetero Mar 13 '12 at 22:06
4

there is a multilineEntryElement code piece at https://gist.github.com/315408

in my app it looks a bit funky but it works.

Mr W
  • 597
  • 1
  • 7
  • 22
2

I created a MultilineEntryElement by subclassing UIViewElement at https://gist.github.com/4080025

Works pretty well and handles a placeholder. You will need to update it for your specific width.

Dave Weaver
  • 415
  • 2
  • 9
2

I'll throw my hat into the ring. I looked at a couple of the multiline entry element gists out there, and they all had layout issues. I wrote this one https://gist.github.com/akcoder/5723722 to address the layout issues and to also handle orientation changes. This should work on all versions of the iPhone and iPad.

Dan Morphis
  • 1,708
  • 19
  • 23
  • You'll have to implement FindControlOfType which is not included in the gist. Also, it does not support a caption, or look nice as an element on the detail side a split view (too wide). It also does not look good being placed in a grouped section, because the text view is rounded (background clear = true) and the placeholder label background is not clear. Thanks for sharing though! – therealjohn Jun 17 '13 at 18:50
  • Sorry for forgetting to include the FindControlOfType piece. When I tested the code it looked fine in both a grouped and plain view. I'm not sure what happened. I left my previous position so I don't have access to that code anymore so I won't be able to update the gist with the FindControlOfType code :( – Dan Morphis Jun 19 '13 at 17:46