Skip to content

Commit

Permalink
Added iOS hack to preserve some UIKit members when Linking
Browse files Browse the repository at this point in the history
  • Loading branch information
praeclarum committed Apr 30, 2014
1 parent 3377684 commit d7bdc43
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 9 deletions.
20 changes: 18 additions & 2 deletions samples/Bind.iOS/Bind.iOS.Sample.csproj
Expand Up @@ -21,9 +21,11 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<MtouchLink>None</MtouchLink>
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
<MtouchDebug>true</MtouchDebug>
<MtouchI18n>
</MtouchI18n>
<MtouchArch>ARMv7</MtouchArch>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
<DebugType>full</DebugType>
Expand All @@ -32,9 +34,11 @@
<DefineConstants>__MOBILE__;__IOS__;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<MtouchLink>None</MtouchLink>
<ConsolePause>false</ConsolePause>
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
<MtouchI18n>
</MtouchI18n>
<MtouchArch>ARMv7</MtouchArch>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -48,6 +52,9 @@
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
<MtouchDebug>true</MtouchDebug>
<CodesignKey>iPhone Developer</CodesignKey>
<MtouchI18n>
</MtouchI18n>
<MtouchArch>ARMv7</MtouchArch>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
<DebugType>full</DebugType>
Expand All @@ -59,6 +66,9 @@
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
<ConsolePause>false</ConsolePause>
<CodesignKey>iPhone Developer</CodesignKey>
<MtouchI18n>
</MtouchI18n>
<MtouchArch>ARMv7</MtouchArch>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Ad-Hoc|iPhone' ">
<DebugType>full</DebugType>
Expand All @@ -72,6 +82,9 @@
<BuildIpa>true</BuildIpa>
<CodesignProvision>Automatic:AdHoc</CodesignProvision>
<CodesignKey>iPhone Distribution</CodesignKey>
<MtouchI18n>
</MtouchI18n>
<MtouchArch>ARMv7</MtouchArch>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'AppStore|iPhone' ">
<DebugType>full</DebugType>
Expand All @@ -84,6 +97,9 @@
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
<CodesignProvision>Automatic:AppStore</CodesignProvision>
<CodesignKey>iPhone Distribution</CodesignKey>
<MtouchI18n>
</MtouchI18n>
<MtouchArch>ARMv7</MtouchArch>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
Expand Down
34 changes: 29 additions & 5 deletions src/Bind.cs
Expand Up @@ -153,10 +153,10 @@ void AddChangeNotificationEventHandler ()
npc.PropertyChanged += HandleNotifyPropertyChanged;
}
else {
var added = AddHandlerForFirstExistingEvent (member.Name + "Changed", "EditingDidEnd", "ValueChanged", "Changed");
if (!added) {
Debug.WriteLine ("Failed to bind to change event for " + target);
}
AddHandlerForFirstExistingEvent (member.Name + "Changed", "EditingDidEnd", "ValueChanged", "Changed");
// if (!added) {
// Debug.WriteLine ("Failed to bind to change event for " + target);
// }
}
}
}
Expand All @@ -175,8 +175,8 @@ bool AddHandlerForFirstExistingEvent (params string[] names)
(EventHandler)HandleAnyEvent :
CreateGenericEventHandler (ev, () => HandleAnyEvent (null, EventArgs.Empty));

Debug.WriteLine ("ADD HANDLER {0} to {1}", eventInfo, target);
ev.AddEventHandler(target, eventHandler);
Debug.WriteLine ("BIND: Added handler for {0} on {1}", eventInfo.Name, target);
return true;
}
}
Expand Down Expand Up @@ -225,6 +225,8 @@ void UnsubscribeFromChangeNotificationEvent ()

eventInfo.RemoveEventHandler (target, eventHandler);

Debug.WriteLine ("BIND: Removed handler for {0} on {1}", eventInfo.Name, target);

eventInfo = null;
eventHandler = null;
}
Expand Down Expand Up @@ -519,5 +521,27 @@ public override void Unbind ()
bindings.Clear ();
}
}

#if __IOS__
[MonoTouch.Foundation.Preserve]
static class PreserveEventsAndSettersHack
{
[MonoTouch.Foundation.Preserve]
static void Hack ()
{
var l = new MonoTouch.UIKit.UILabel ();
l.Text = l.Text + "";

var tf = new MonoTouch.UIKit.UITextField ();
tf.Text = tf.Text + "";
tf.EditingDidEnd += delegate {};
tf.ValueChanged += delegate {};

var vc = new MonoTouch.UIKit.UIViewController ();
vc.Title = vc.Title + "";
vc.Editing = !vc.Editing;
}
}
#endif
}

4 changes: 2 additions & 2 deletions src/Bind.iOS/Bind.iOS.csproj
Expand Up @@ -17,13 +17,12 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<DefineConstants>DEBUG;__IOS__</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
Expand All @@ -34,6 +33,7 @@
<Command type="AfterBuild" command="cp ${TargetFile} ../bin/" workingdir="${SolutionDir}" />
</CustomCommands>
</CustomCommands>
<DefineConstants>__IOS__</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
Expand Down

0 comments on commit d7bdc43

Please sign in to comment.