RSS

MonoTouch Tip #2 – Adding Keyboard Support.

To add support for keyboard input to your MonoTouch application you must first register for Notifications after your view as loaded.

NSObject obs1;

public override void ViewDidLoad ()
{
obs1 = NSNotificationCenter.DefaultCenter.AddObserver (
"UIKeyboardDidShowNotification", KeyboardUpNotification);
}

The next task is to set up the Notification method.

private void KeyboardUpNotification (NSNotification notification)
{
//Get the bounds of the keyboard...
RectangleF r = UIKeyboard.BoundsFromNotification(notification);
}

The keyboard bounds can then be used to move the view to keep textbox inputs visible. You will also need to wire up the textbox ShouldReturn event for each of your input text-boxes to scroll the view down when you are finished with the keyboard.

 
Leave a comment

Posted by on May 11, 2010 in MonoTouch

 

MonoTouch Tip #1 – Creating a simple Message Box function

Even in the most simple applications you will often need to display messages to the user. Hopefully it will be just useful information and only occasionally an error message. If you have created a single view iPhone application it may be an overkill to create an error handling framework. This sample will add simple Message Box functionality to your view class.

[Flags]
internal enum MButtons
{
OK = 1,
Cancel = 2
};

private void MessageBox(string title, string message, MButtons buttons)
{
using(UIAlertView alert = new UIAlertView())
{
alert.Title = title;
alert.Message = message;

if((buttons & MButtons.OK) == MButtons.OK)
{
alert.AddButton("OK");
}

if((buttons & MButtons.Cancel) == MButtons.Cancel)
{
alert.AddButton("Cancel");
}

alert.Show();
}
}

Here is an example using this function:

MessageBox("My Message Box",
"This could be information or error details",
MButtons.OK | MButtons.Cancel);

I have found this snippet of code extremely useful when creating a quick application or prototyping a larger interface.

 
Leave a comment

Posted by on May 11, 2010 in MonoTouch

 

My first iPhone application.

Pressure Logo
This is my first venture into iPhone development, so it’s a very simple app for recording your vehicle tyre pressures. I also included a handy Bar to PSI converter. I used C Sharp as the programming language and Mono Touch. The most difficult functionality to get working correctly was moving the view to make way for the keyboard and showing the textboxes just above it.  I’m working on the next version now which will give multi vehicle functionality. I will let you know how that is going in the next few days. Click on the image to view version 1.0 on the App store:

 
Leave a comment

Posted by on May 8, 2010 in MonoTouch

 

Welcome to my new blog!

Welcome to my new blog. I intend to update this regularly with my tales of learning the art of Smart Phone App development. Smart Phone App development is a hobby and my main job is as a Silverlight Developer on a major document management solution. See my about page for more information on my career. The Smart Phone market has really taken off in the last few years and I thought it was about time I got involved. The iPhone and iPad platform is challenging for a programmer used to larger formats and I will be looking at learning Objective C in the next few months. Maybe you will want to follow along with my journey and even offer some helpful comments along the way.