EzDevInfo.com

monotouch interview questions

Top monotouch frequently asked interview questions

Looking to understand the iOS UIViewController lifecycle

Could you explain me the correct manner to manage the UIViewController lifecycle?

In particular, I would like to know how to use Initialize, ViewDidLoad, ViewWillAppear, ViewDidAppear, ViewWillDisappear, ViewDidDisappear, ViewDidUnload and Dispose methods in Monotouch for a UIViewController class.

Thank you in advance.


Source: (StackOverflow)

How can I launch multiple instances of MonoDevelop on the Mac?

I would like to open a new MonoDevelop instance to work on a different project on the Mac, and the OS is currently preventing me from opening a new instance.


Source: (StackOverflow)

Advertisements

How to force a UIViewController to Portait orientation in iOS 6

As the ShouldAutorotateToInterfaceOrientation is deprecated in iOS 6 and I used that to force a particular view to portrait only, what is the correct way to do this in iOS 6? This is only for one area of my app, all other views can rotate.

Thank you.


Source: (StackOverflow)

How to decide between MonoTouch and Objective-C?

After sitting through a session today on Mono at a local .Net event, the use of MonoTouch was 'touched' upon as an alternative for iPhone development. Being very comfortable in C# and .Net, it seems like an appealing option, despite some of the quirkiness of the Mono stack. However, since MonoTouch costs $400, I'm somewhat torn on if this is the way to go for iPhone development.

Anyone have an experience developing with MonoTouch and Objective-C, and if so is developing with MonoTouch that much simpler and quicker than learning Objective-C, and in turn worth the $400?


Source: (StackOverflow)

How to speed up MonoTouch compilation time?

It is well known that

If compiling takes even 15 seconds, programmers will get bored while the compiler runs and switch over to reading The Onion, which will suck them in and kill hours of productivity.

Our MonoTouch app takes 40 seconds to compile on Macbook Air in Debug/Simulator configuration.

We have about 10 assemblies in the solution.
We're also linking against some native libraries with gcc_flags.

I'm sure there are ways to optimize compilation time that I'm not aware of, which might have to do with references, linker, whatever.

I'm asking this question in hope that someone with better knowledge than me will compile (no pun intended) a list of tips and things to check to reduce MonoTouch compilation time for debug builds.

Please don't suggest hardware optimizations or optimizations not directly related to MonoTouch.


Source: (StackOverflow)

How to force Monotouch AOT Compiler to see a nested generic method?

I've had to jump through hoops, but I've almost managed to get ServiceStack working on iOS with Monotouch in my project. One runtime JIT exception is holding out:

System.ExecutionEngineException: Attempting to JIT compile method 'ServiceStack.Text.Json.JsonTypeSerializer:GetWriteFn<int> ()' while running with --aot-only. 

The offending code is quite simple:

   internal WriteObjectDelegate GetWriteFn<T>()
    {
        return JsonWriter<T>.WriteFn();
    }

As a test, I modified the SS code to make the internal methods and types public and included the following in the startup code of my project (to actually get called).

var ick = ServiceStack.Text.Json.JsonWriter<int>.WriteFn();
var erk = ServiceStack.Text.Json.JsonTypeSerializer.Instance.GetWriteFn<int>();

This still doesn't alert the AOT for some reason, I get the exception when the code above executes! Is this because the generic parameter is a value type? Or is it because these are static classes and methods? How can I force Monotouch to AOT the methods above?

The SS code in question is in JsonTypeSerializer.cs and JsonWriter.Generic.cs at: https://github.com/ServiceStack/ServiceStack.Text/tree/master/src/ServiceStack.Text/Json


Source: (StackOverflow)

Official way to create iOS icons? [closed]

I find it hard to believe that every developer creates their icons manually in various different ways but if that is the case, that is fine. I was wonder what the standard was for creating iOS icons (home screen icons, etc.)


Source: (StackOverflow)

Is this a bug in MonoTouch GC?

Note: I've created a simple project—you can see how switching types between UIButton and CustomButton in storyboard changes GC behavior.

I'm trying to get my head wrapped around MonoTouch garbage collector.
The issue is similar to the one fixed in MT 4.0, however with inherited types.

To illustrate it, consider two view controllers, parent and child.

Child's view contains a single UIButton that writes to console on tap.
Controller's Dispose method throws an exception so it's hard to miss.

Here goes child view controller:

public override void ViewDidLoad ()
{
    base.ViewDidLoad ();

    sayHiButton.TouchUpInside += (sender, e) =>
        SayHi();
    }
}

void SayHi()
{
    Console.WriteLine("Hi");
}

protected override void Dispose (bool disposing)
{
    throw new Exception("Hey! I've just been collected.");
    base.Dispose (disposing);
}

Parent view controller just presents child controller and sets a timer to dismiss it and run GC:

public override void ViewDidLoad ()
{
    base.ViewDidLoad ();

    var child = (ChildViewController)Storyboard.InstantiateViewController("ChildViewController");

    NSTimer.CreateScheduledTimer(2, () => {
        DismissViewController(false, null);
        GC.Collect();
    });

    PresentViewController(child, false, null);
}

If you run this code, it predictably crashes inside ChildViewController.Dispose() called from its finalizer because child controller has been garbage collected. Cool.

Now open the storyboard and change button type to CustomButton. MonoDevelop will generate a simple UIButton subclass:

[Register ("CustomButton")]
public partial class CustomButton : UIButton
{
    public CoolButton (IntPtr handle) : base (handle)
    {
    }

    void ReleaseDesignerOutlets()
    {
    }
}

Somehow changing the button type to CustomButton is enough to trick garbage collector into thinking child controller is not yet eligible for collection.

How is that so?


Source: (StackOverflow)

Is MonoGame reliable?

I'm looking for a cross-platform game development framework. MonoGame looks easy to learn and fast to develop, but I see most of the games featured at their page do not work, or have a lot of bugs.

Can anyone explain if MonoGame is reliable for ios/droid professional mobile game development?


Source: (StackOverflow)

Write to a File in Monotouch

How would I create and write to a file in a Monotouch iPhone app?

The file should persist between application launches, so I guess it has to be placed somewhere in the App bundle ( documents or resources?).


Source: (StackOverflow)

Extended UIButton border is not initially drawn

I am trying to create a custom UIButton which extends from UIButtonType.RoundedRect.

My added functionality is working, but there is an issue with the initial rounded border state of my button. The border of my extended button is not drawn until after it has been tapped.

Before-After Screenshot

Update (January 24th 2013): Added the result of red background test, as requested by Richard Marskell, which concludes only the label of the button is drawn. BackgroundColor = UIColor.Red;

Red Background Test, Before-After Screenshot

Below is my source code for creating my custom button.

public class TestView : UIView
{
    public TestView(IntPtr p) : base(p) { }

    public TestView(RectangleF bounds)
    {
        Frame = bounds;
        BackgroundColor = UIColor.White;

        UIButton button1 = new UIButton(UIButtonType.RoundedRect);
        button1.Frame = new RectangleF(20,20,100,50);
        button1.SetTitle("Button 1", UIControlState.Normal);
        AddSubview(button1); // Drawn Correctly

        MyButton button2 = new MyButton();
        button2.Frame = new RectangleF(20,90,100,50);
        button2.SetTitle("Button 2", UIControlState.Normal);
        AddSubview(button2); // Only drawn correctly after Tap

        // EDIT: Added to test Miguel's theory
        UIButton button3 = UIButton.FromType(UIButtonType.RoundedRect);
        button3.Frame = new RectangleF(20,160,100,50);
        button3.SetTitle("Button 3", UIControlState.Normal);
        AddSubview(button3); // Drawn Correctly
    }
}

public class MyButton : UIButton
{
    public MyButton() : base(UIButtonType.RoundedRect) { }
}
  • I'm just not sure how to force the border to be drawn correctly on loading of the view.
  • I don't need a button of type UIButtonType.Custom, as I don't want to style the button myself.
  • When I debug I the type of MyButton is correctly set to UIButtonType.RoundedRect.
  • The UIButton base properties of MyButton (button2) match the properties of the UIButton instance (button1).

Debug

How can I resolve this issue?


Update (January 31st 2013): Herman Schoenfeld provided a suitable solution for this bug.


Source: (StackOverflow)

Monotouch or Titanium for rapid application development on IPhone?

As a .Net developer I always dreamed for the possibility to develop with my existing skills (c#) applications for the Iphone.

Both programs require a Mac and the Iphone Sdk installed.

Appcelerator Titanium was the first app I tried and it is based on exposing some Iphone native api to javascript so that they can be called using that language.

Monotouch starts at $399 for beeing able to deploy on the Iphone and not on the Iphone simulator while Titanium is free.

Monotouch (Monodevelop) has an Ide that is currently missing in Titanium (but you can use any editor like Textmate, Aptana...)

I think both program generate at the end a native precompiled app (also if I am not sure about the size of the final app on the Iphone as I think the .Net framework calls are prelilnked at compilation time in Monotouch).

I am also not sure about the full coverage of all the Iphone api and features.

Titanium has also the advantage to enable Android app development but as a c# developer I still find Monotouch experience more like the Visual Studio one.

Which one would you choose and what are your experiences on Monotouch and Titanium?


Source: (StackOverflow)

How do I launch multiple instances of Xamarin Studio on the Mac? [duplicate]

This question already has an answer here:

I'd like to have multiple copies of Xamarin Studio running simultaneously. Once one copy is running, double-clicking the Xamarin Studio icon in /Applications or clicking the currently-running Dock icon simply brings the current one to the foreground.


Source: (StackOverflow)

Better MonoTouch crashes with TestFlight

We've hooked up TestFlight and the TestFlight SDK with MonoTouch and so far it's working great.

One thing we've noticed is that the crash reports are more geared towards Obj-C apps.

They look like this after you upload a zipped dSYM file:

0 OurApp 0x007a7116 testflight_backtrace + 170
1 OurApp0x007a7c3c TFSignalHandler + 208
2 libsystem_c.dylib 0x34f68538 _sigtramp + 48
3 libsystem_c.dylib 0x34f5df5a pthread_kill + 54
4 libsystem_c.dylib 0x34f56fea abort + 94
5 OurApp 0x007793b3 monoeg_g_logv (goutput.c:137)
6 OurApp 0x0077941f monoeg_g_log (goutput.c:147)
7 OurApp 0x005f1393 get_numerous_trampoline (aot-runtime.c:3447)
8 OurApp 0x005f1b2f mono_aot_get_imt_thunk (aot-runtime.c:3576)
9 OurApp 0x006e2c83 initialize_imt_slot (object.c:1247)
10 OurApp 0x006e321f build_imt_slots (object.c:1371)
11 OurApp 0x006e356f mono_vtable_build_imt_slot (object.c:1439)
12 OurApp 0x005fcf83 mono_convert_imt_slot_to_vtable_slot (mini-trampolines.c:198)
13 OurApp 0x005fd50f common_call_trampoline (mini-trampolines.c:333)
14 OurApp 0x005fe573 mono_vcall_trampoline (mini-trampolines.c:644)
15 OurApp 0x0056a68f generic_trampoline_vcall (mscorlib.dll.6.s:194345)
16 OurApp 0x00416b4f System_Collections_Generic_List_1__ctor_System_Collections_Generic_IEnumerable_1_T (mscorlib.dll.6.s:32014)
17 OurApp 0x0026955b System_Linq_Enumerable_ToList_TSource_System_Collections_Generic_IEnumerable_1_TSource (System.Core.dll.6.s:1917)

So you can tell the general C# function where the crash occurred. (Note: this crash was a bug in MonoTouch 5.0.1 where Linq generics were messed up, seems to be fixed in 5.0.2)

It would be nice to get the full C# stack trace in here, any thoughts on how to do that? I could hook into AppDomain.UnhandledException and put a try-catch around my static void Main method, but wondered if there is a way to report the stack trace out to TestFlight.


Source: (StackOverflow)

Is there a way to mix MonoTouch and Objective-C?

I'd like to know if there is a way to mix C# and Obj-C code in one project. Specifically, I'd like to use Cocos2D for my UI in Obj-C and call some MonoTouch C#-Library that does some computations and get some values back. Is there a way to do this? Or maybe the other way around, i. e. building in MonoTouch and calling Cocos2D-functions? Thanks.


Source: (StackOverflow)