user472292
user472292

Reputation: 329

MonoTouch UITableView Questions

I am using a UITableView in my application. I have the following questions:

  1. I need to know when a user selected a row. From what I gather, I need to write a class that implements the UITableViewDelegate. Then I need to override the RowSelected method. Is there anyway to do this in my controller (as opposed to creating another class). It seems like overkill. Something like myTableView.RowSelected += MyMethod(). I'm not sure why RowSelected is not an event in the first place...

  2. I want to clip the title of a UITableView (text in the header) on the left hand side (default is the right). I know you can set the LineBreakMode, but it seems like I have to do this in the GetViewForHeader method (creating my own UIView that is in the header). Is there a simpler way to do this?

Upvotes: 1

Views: 459

Answers (1)

poupou
poupou

Reputation: 43543

MonoTouch offers (close to) full bindings to the iOS SDK - i.e. some stuff already exists in the .NET base class library and are not duplicated (but we'll add them if you need them, just fill a bug report in such cases).

In general those bindings are very close to the original API (either C or Objective-C based) since:

  • the binding process is largely automated using the btouch tool supplied with MonoTouch (which you can use to bind your own ObjectiveC API);

  • it really helps porting existsing code, finding code samples and API documentation (Apple developer site, blogs, questions here on stackoverflow.com...)

I'm not sure why RowSelected is not an event in the first place...

Events, like .NET provides, do not exists in Objective-C. In many (but not all) cases MonoTouch added .NET-style events that allows you to avoid defining your own xxxDelegates types. In general the events are named On + the name of the delegate selector.

Is there a simpler way to do this?

In case of UITableView the (ObjectiveC) API is IMHO a bit confusing - but there's an alternative: MonoTouch.Dialog. It makes working with tables much easier and has a .NET-friendly API.

p.s. please try to ask only one question per entry since you can't mark multiple anwers as accepted. It also help people who looks for similar questions/answers on the site.

Upvotes: 2

Related Questions