Can EntryElement be multiline on MonoTouch.Dialog?
Asked Answered
K

4

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.

Kilmarnock answered 12/3, 2012 at 20:12 Comment(0)
M
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).

Myungmyxedema answered 12/3, 2012 at 21:31 Comment(1)
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?Kilmarnock
S
4

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

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

Salena answered 30/8, 2012 at 14:27 Comment(0)
T
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.

Twiggy answered 15/11, 2012 at 17:45 Comment(1)
float containerWidth = UIScreen.MainScreen.Bounds.Width;Thermoluminescence
I
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.

Indonesia answered 6/6, 2013 at 18:26 Comment(2)
You'll have to implement FindControlOfType<T> 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!Erland
Sorry for forgetting to include the FindControlOfType<T> 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 :(Indonesia

© 2022 - 2024 — McMap. All rights reserved.