Is Monotouch.Dialog a suitable replacement for all UITableviews?
Asked Answered
H

2

5

This question is mainly targeted towards Miguel as the creator of MT.Dialog but I would like to hear opinions of others as well. I'm currently refactoring a project that has many table views. I'm wondering if I should replace All of them with MT.Dialog.

My pros are:

  • easy to use
  • simple code
  • hope that Xamarin will offer it cross platform one day

Cons:

  • my cells are complete custom made. Does it make sense in that case?
  • performance? Is that an issue?
  • breaking the MVC paradigms (source no longer separated from view and controller)

Is it in general better to just use MT.Dialog or inherit from it for specific use cases? What are your experiences?

Hasidism answered 25/2, 2012 at 15:29 Comment(1)
I tend to use it for cases where I need to do data entry in a table. For normal display-only tables I continue to do them manually.Icarian
C
11

To address some of your questions.

The major difference between MonoTouch.Dialog and UITableView is that with the former you "load" all the data that you want to render upfront, and then forget about it. You let MonoTouch.Dialog take care of rendering it, pushing views and taking care of sections/elements. With UITableView you need so provide callback methods for returning the number of sections, the titles for the sections and the data itself.

UITableView has the advantage that to render say a million rows with the same size and the same cells, you dont really have to load all the data upfront, you can just wait to be called back. That being said, this breaks quickly if you use cells with different heights, as UITableView will have to query for the sizes of all of your rows.

So in short:

(1) yes, even if you use custom cells, you will benefit from shorter code and a simpler programming model. Whether you use the other features of it or not, is up to you.

(2) For performance, the issue boils down to how many rows you will have. Like I mentioned before, if you are browsing a potentially large data set, you would have to load all of those cells in memory up front, or like TweetStation, add features to load "on-demand".

The reality is that it will consume more memory, because you need to load your data in MonoTouch.Dialog. Your best optimization technique is to keep your Elements very lightweight. Tweetstation for example uses a "TweetElement" that merely holds the ID to the tweet, and loads the actual contents on demand, to keep the size of the TweetElement in memory very small.

With UITableView, you do not pay for that price. But if you are not using a database of some sort, the data will still be in memory.

If your application calls for the data to be in memory, then you might as well move the data to be elements and use that as your model.

(3) This is a little bit of a straw man. Your data "source" is never really independent of UIKit. I know that people like to talk about these models as being reusable, but in practice, you wont ever be able to reuse a UITableViewSource as a source for anything but a UITableView. It's main use is to support scalable controls that do not require data to be loaded in memory up-front, it is not really about separating the Model from the View.

So what you really have is an adaptor class that bridges the world of the UITableView with your actual data model (a database, an XML list, an in-memory array, a Redis connection).

With UITableView, your adaptor code lives in the constructor and the UITableViewSource. With MonoTouch.Dialog your adatpro code lives in the code that populates the initial RootElement to DialogViewController.


So there are reasons to use UITableView over MonoTouch.Dialog, but it is none of those three Cons.

Cervelat answered 26/2, 2012 at 18:5 Comment(2)
I see. In the current implementation data is coming from a database but all of the current child nodes reside inside the table view controller in memory. This means that I could just as well switch to MT.Dialog. What did you mean by holding the element small? If your element only holds the ID, where is the rest of the data stored? Does it matter where it is stored? Is MT.Dialog using queuable cells or does it generate all cells in advance?Hasidism
@Miguel How about the "hope that Xamarin will offer it cross platform one day" bit?Hodometer
S
4

I use MonoTouch.Dialog (and it's brother QuickDialog for objc) pretty much every time I use a tableview. It does help a lot to simplify the code, and gives you a better abstraction of a table.

There's one exception, though, which is when the table will have thousands and thousands of rows, and the data is in a database. MT.D/QD requires you to load all the data upfront, so you can create the sections, and that's simply too slow if you don't already have the objects in memory.

Regarding "breaking MVC", I kind of agree with you. I never really use the reflection bindings in MT.D because of that fact. Usually I end up creating the root from scratch in code, or use something like JSON (in my fork https://github.com/escoz/MonoMobile.Forms), so that my domain objects don't need to know about MT.D.

Straight answered 25/2, 2012 at 20:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.