Re: [MonoTouch] How do you actually listen to an UIScrollView scrolling
Ah, I was afraid of that. Really, I have to say, it's not much of an API design when there are two ways of doing things and they silently break and cancel each other out like this. We'll consider our options but as suspected it'll probably not be possible to support both then. Thanks Nic! / V -- View this message in context: http://monotouch.2284126.n4.nabble.com/How-do-you-actually-listen-to-an-UIScrollView-scrolling-tp4658518p4658524.html Sent from the MonoTouch mailing list archive at Nabble.com. ___ MonoTouch mailing list MonoTouch@lists.ximian.com http://lists.ximian.com/mailman/listinfo/monotouch
Re: [MonoTouch] Autosize our app for iPhone 5...
I hate to reply to my own message, but for those of you who, like me, keep hitting the brick wall and not getting the auto-resizie to work - here's the answer: Give up, there is no such thing as magically expand yourself to parent size layout manager style like in CSS, Java Swing, or Most Every Other Toolkit Known to Man. Instead, what you do is *always* use fixed positioning for everything. The auto-resize thing only comes in to play when, well, the View is *resized*. To get your table in a scrollview expand on to the full screen on both iPhone4 and 5, and behave accordingly when the in-call status bar is toggled, you'd do something like // set container to full size of screen, fixed positions ftw UIViewScrollView container = new UIScrollView(0,0, View.Frame.Width, View.Frame.Height); // content size to some large table size container.ContentSize = new SizeF(table.Frame.Width, table.Frame.Height) // how to resize the scrollview when the status bar is toggled container.AutoresizingMask = UIViewAutoresizing.FlexibleHeight // add the table container.AddSubview(table); I hope this helps someone in the future, it would have saved me quite a lot time :-) / Vic -- View this message in context: http://monotouch.2284126.n4.nabble.com/Autosize-our-app-for-iPhone-5-tp4657080p4657146.html Sent from the MonoTouch mailing list archive at Nabble.com. ___ MonoTouch mailing list MonoTouch@lists.ximian.com http://lists.ximian.com/mailman/listinfo/monotouch
[MonoTouch] Autosize our app for iPhone 5...
Dear list, So iPhone 5 is on its way, and suddenly we have a new resolution to deal with. Well, a quick peek on the source for my app shows me that I'm not ready. At all. I have hard coded height/width everywhere. So I try the mighty Google trying to understand how this AutoresizingMask stuff, nd just as last time I really don't get it. That most examples are for using IB doesn't really help either (screenshots like http://i.stack.imgur.com/uQExw.png just makes me want to stab my head with a fork). It would be great if someone at Xamarin could write a recipe on how to properly implement AutoResizing, but until then - I can't even get the most basic things to work! From what I understand, what I want to do is anchor a view at X,Y and then let it resize itself to fit the screen, then relatively place stuff in it. Here's how you not do auto resize a view: public class TestView : UIViewController { public override void ViewDidLoad () { View.BackgroundColor = UIColor.Blue; var test = new UIView(new RectangleF(10, 10, 200, 200)) { BackgroundColor = UIColor.Black, AutoresizingMask = UIViewAutoresizing.FlexibleBottomMargin }; View.AddSubview(test); } } This, in my world, would anchor the black view at 10,10 have a minimum of 200,200 pixels and then resize its bottom to fit the screen. It of course doesn't work at all because I'm probably thinking layout manager when I should be thinking different. I must be missing something obvious. Short version: I have a UIView. Right now it's at a fixed position at 0,90 with a 320px width and 370px height. When the iPhone 5 is released, I'll need that 370 to continue down to fill the whole screen. How do I do that? Any help is as always very much appreciated! -- View this message in context: http://monotouch.2284126.n4.nabble.com/Autosize-our-app-for-iPhone-5-tp4657080.html Sent from the MonoTouch mailing list archive at Nabble.com. ___ MonoTouch mailing list MonoTouch@lists.ximian.com http://lists.ximian.com/mailman/listinfo/monotouch
Re: [MonoTouch] What does iOS do to my poor app in the background?
Rolf Bjarne Kvinge to the rescue again, that did clear some things up... I was somehow under the impression that iOS would just randomly reclaim memory from the app while it was sleeping - that DidReceiveMemoryWarning was only called while the app was in the foreground. Silly me. Many of the objects I keep in memory are for performance reasons, and while I could always free them when the app enters background I'd probably have to restore then when the user returns, which would make for a noticeable delay. I'll just free them in DidReceiveMemoryWarning then. Finally things are starting to fall into place, this is much easier than believing that iOS would just randomly butcher parts of your app, super thanks! ... that does leave the seemingly random freezes as something of a mystery, but I'll probably figure that out with your debugging tips. Cool! / V -- View this message in context: http://monotouch.2284126.n4.nabble.com/What-does-iOS-do-to-my-poor-app-in-the-background-tp4655601p4655628.html Sent from the MonoTouch mailing list archive at Nabble.com. ___ MonoTouch mailing list MonoTouch@lists.ximian.com http://lists.ximian.com/mailman/listinfo/monotouch
[MonoTouch] What does iOS do to my poor app in the background?
Dear list, App works fine and Monotouch is awesome. The final showstopper is the silly user decides to do something else (gasp!) and puts the app in the background, and when restored later on one of three things happens: 1 App returns to where it was, great! 2 App has been killed by iOS in the background and stars anew, can live with that! 3 Something in-between, and the app freezes. This isn't very good. Up until now I haven't put much thought into the whole background/foreground thing and find it surprisingly hard to come by any good resources how to do this. The reason for the app freezing is probably me not properly restoring the state of the application, but exactly what is it I need to save/restore? The app I'm working on isn't the most complicated thing ever, but it's not Hello ViewController either. For one thing, I have quite a few objects in memory that responds to events. If iOS decides to kill them off, I can see why the app freezes. If that's even possible? From what I understand, iOS can reclaim memory (without killing the application), but exactly what would that include? In memory objects? ViewControllers? Subviews? For me, it all comes down to this: When the user returns to the app, I need to know what has iOS done to my application so I know how to respond. Right now I answer that question with I have no idea and just hope scenario 1 or 2 plays out. Any hints or docs on this is very very very much appreciated. This is, I think, the last issue before I get super rich selling my app for $0 on the appstore. / V -- View this message in context: http://monotouch.2284126.n4.nabble.com/What-does-iOS-do-to-my-poor-app-in-the-background-tp4655601.html Sent from the MonoTouch mailing list archive at Nabble.com. ___ MonoTouch mailing list MonoTouch@lists.ximian.com http://lists.ximian.com/mailman/listinfo/monotouch
Re: [MonoTouch] Correct way to cache and restore a UIViewController
Tomasz Cielecki wrote I guess this should work, but mind that your app might run out of memory if you cache a lot of views in the memory. Also keep in mind that while the application is in suspended mode iOS may purge the memory of the application and you will have to reload the views anyways. Ah, well aware of that! I simplified it a little bit, in reality the cache Get method works something like this public static T GetT() where T : class, new() { string key = typeof(T).ToString(); T data = null; if (CachedViews.ContainsKey(key)) data = CachedViews[key] as T; if (data == null) // not in cache or eaten by a grue { data = new T(); CachedViews[key] = data; } return data; } so... var controller = ViewControllerCache.GetMyFantasticView(); ...would give me MyFantasticView if it's in the cache, or a new instance if it's not. And that made me feel very smart for a few minutes. It all starts to fall apart if I save a viewcontroller in the cache and then push it onto the navigator later, deeper down the navigation hierarchy. Tomasz Cielecki wrote The normal approach is as you said yourself to create the view when needed and dispose of it when it is not needed anymore. I am not sure what the time consuming part of your views are, but usually my views load instantly and the loading of the data to be put into the views is what consumes most of the time. So maybe a better approach to this could be to save the state of the data in the view rather than the view itself. If it is really the view that is taking that much time to load, then try to see if it can be optimized. Hmm, that's an idea worth exploring. For some reason I can't quite get the profiling tools to work so I'm stuck with adding stopwatches here and there, making it somewhat tricky to figure out what's really slowing down the transitions. And it's not like it's unbearable, but having just a single second delay between views really make the whole experience so much worse. Xamarin people: Please give us a guide on how to best optimize our apps ;-) On Thu, Jun 21, 2012 at 1:11 PM, victoria lt;iminurbase@gt; wrote: Dear list, Short version: What's the correct way to load a UIViewController when the application starts, and then restore it (much) later? * I found creating UIViewControllers with somewhat complex Views to be a fairly expensive operation, so instead of just creating and pushing them onto the Navigator when needed, I had the idea to load all heavy views into a simple object cache when the app starts (with a nice loading screen), and then push/pop them at will while keeping them in memory. It works something like this: 1 AppStartUp |--- cache[finalView] = new ComplexViewController(); |--- push Menu A onto the navigator | 2 Menu A Controller | --- user makes some kind of selection | --- (cache[finalView] as ComplexViewController).UpdateViewWithSelectionFromMenuA() |--- push Menu B onto the navigator | 3 Menu B Controller | --- user makes some kind of selection | --- (cache[finalView] as ComplexViewController).UpdateViewWithSelectionFromMenuB() |--- push cache[finalView] onto the navigator | 4 ComplexViewController | --- OMG Ponies! This method at first seemed to work great, and made the transition between Menu B and ComplexViewController *a lot* smoother. However, things started to fall apart recently with stuff going missing from the views in the cache. So, I started adding lots of SetNeedsDisplay() in their ViewWillAppear methods, and this somewhat worked - except for UITables. And some custom controls. I'm fairly certain I've gone down the wrong path here, so are there any best practices for doing what I'm trying to accomplish? Any help or hints would be much appreciated! / V -- View this message in context: http://monotouch.2284126.n4.nabble.com/Correct-way-to-cache-and-restore-a-UIViewController-tp4655514.html Sent from the MonoTouch mailing list archive at Nabble.com. ___ MonoTouch mailing list MonoTouch@.ximian http://lists.ximian.com/mailman/listinfo/monotouch -- Med Venlig Hilsen / With Best Regards Tomasz Cielecki http://ostebaronen.dk ___ MonoTouch mailing list MonoTouch@.ximian http://lists.ximian.com/mailman/listinfo/monotouch -- View this message in context: http://monotouch.2284126.n4.nabble.com/Correct-way-to-cache-and-restore-a-UIViewController-tp4655514p4655521.html Sent from the MonoTouch mailing list archive at Nabble.com. ___ MonoTouch mailing list MonoTouch@lists.ximian.com http://lists.ximian.com/mailman/listinfo/monotouch
[MonoTouch] Best way of cropping out the transperancy of a PNG image?
Hello list! I have a bunch of transparent PNG images, all the same size - I need to crop out the transparent part around the actual content. It's been asked on stack overflow before ( http://stackoverflow.com/questions/2451225/programmatically-trimming ) with some more or less working solutions in objc, but I can't help to think that there's a better way. So, have anyone done this successfully in Monotouch? Actually cropping the image probably isn't needed in most cases, as long as one could get the bounding box of the transparent part you could just justify the frame. Any thoughts on this or code to share would be much appreciated! / Victoria -- View this message in context: http://monotouch.2284126.n4.nabble.com/Best-way-of-cropping-out-the-transperancy-of-a-PNG-image-tp4620898.html Sent from the MonoTouch mailing list archive at Nabble.com. ___ MonoTouch mailing list MonoTouch@lists.ximian.com http://lists.ximian.com/mailman/listinfo/monotouch
Re: [MonoTouch] CancelAsync on DownloadDataAsync crashes monotouch?
That is odd, I can't really make it more of a test case because that's all there is. If I start a clean solution and a console project with just class MainClass { public static void Main (string[] args) { string file = http://www.kernel.org/pub/linux/kernel/v2.0/linux-2.0.1.tar.bz2;; System.Net.WebClient client = new System.Net.WebClient(); client.DownloadDataAsync(new System.Uri(file)); client.CancelAsync(); // still kabooms } } I get the same crash. Are we using the same version? I'm on 2.10.9 (Stable) and I'm not really in a position where I'd feel comfortable switching to the beta branch... but if it works on beta and not stable then I guess I can just wait for it to be fixed, the project I'm working on isn't due for release for quite a while :-) Rolf Bjarne Kvinge wrote Hi, On Mon, Apr 16, 2012 at 10:45 AM, victoria lt;iminurbase@gt; wrote: Hello list, I'm not sure if this is a Monotouch bug or if we're doing something wrong here. We're trying to use System.Net.WebClient to fetch some data async with a nice optional Cancel this download button for the user - however trying to cancel the request blows up everything. Behold: // random somewhat big file to not download string file = http://www.kernel.org/pub/linux/kernel/v2.0/linux-2.0.1.tar.bz2;; WebClient client = new WebClient(); client.DownloadDataAsync(new Uri(file)); client.CancelAsync(); // kaboom I just tried this exact code, and it works fine for me. I've looked at both the exception and our WebClient implementation, and the exception doesn't make much sense - so something is obviously going wrong. I suggest you file a bug with a complete test case, and I'll have a look at it asap. Rolf The code above works just fine on .NET/Windows - also, changing DownloadDataAsync to DownloadStringAsync seems to work as we would expect it to (no kaboom, but we need the raw data so unfortunately we can't use it) Thoughts? Bug? Help? / V -- View this message in context: http://monotouch.2284126.n4.nabble.com/CancelAsync-on-DownloadDataAsync-crashes-monotouch-tp4560900p4560900.html Sent from the MonoTouch mailing list archive at Nabble.com. ___ MonoTouch mailing list MonoTouch@.ximian http://lists.ximian.com/mailman/listinfo/monotouch ___ MonoTouch mailing list MonoTouch@.ximian http://lists.ximian.com/mailman/listinfo/monotouch -- View this message in context: http://monotouch.2284126.n4.nabble.com/CancelAsync-on-DownloadDataAsync-crashes-monotouch-tp4560900p4563814.html Sent from the MonoTouch mailing list archive at Nabble.com. ___ MonoTouch mailing list MonoTouch@lists.ximian.com http://lists.ximian.com/mailman/listinfo/monotouch
[MonoTouch] CancelAsync on DownloadDataAsync crashes monotouch?
Hello list, I'm not sure if this is a Monotouch bug or if we're doing something wrong here. We're trying to use System.Net.WebClient to fetch some data async with a nice optional Cancel this download button for the user - however trying to cancel the request blows up everything. Behold: // random somewhat big file to not download string file = http://www.kernel.org/pub/linux/kernel/v2.0/linux-2.0.1.tar.bz2;; WebClient client = new WebClient(); client.DownloadDataAsync(new Uri(file)); client.CancelAsync(); // kaboom The code above works just fine on .NET/Windows - also, changing DownloadDataAsync to DownloadStringAsync seems to work as we would expect it to (no kaboom, but we need the raw data so unfortunately we can't use it) Thoughts? Bug? Help? / V -- View this message in context: http://monotouch.2284126.n4.nabble.com/CancelAsync-on-DownloadDataAsync-crashes-monotouch-tp4560900p4560900.html Sent from the MonoTouch mailing list archive at Nabble.com. ___ MonoTouch mailing list MonoTouch@lists.ximian.com http://lists.ximian.com/mailman/listinfo/monotouch
Re: [MonoTouch] CancelAsync on DownloadDataAsync crashes monotouch?
Hoh, yes sorry... Running the four lines I posted I get this back: Unhandled Exception: System.Threading.ThreadInterruptedException: Thread interrupted at (wrapper managed-to-native) System.Threading.WaitHandle:WaitOne_internal (System.Threading.WaitHandle,intptr,int,bool) at System.Threading.WaitHandle.WaitOne (Int32 millisecondsTimeout, Boolean exitContext) [0x0] in filename unknown:0 at System.Net.WebAsyncResult.WaitUntilComplete (Int32 timeout, Boolean exitContext) [0x0] in filename unknown:0 at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x0] in filename unknown:0 at System.Net.HttpWebRequest.GetResponse () [0x0] in filename unknown:0 at System.Net.WebClient.GetWebResponse (System.Net.WebRequest request) [0x0] in filename unknown:0 at System.Net.WebClient.ReadAll (System.Net.WebRequest request, System.Object userToken) [0x0] in filename unknown:0 at System.Net.WebClient.DownloadDataCore (System.Uri address, System.Object userToken) [0x0] in filename unknown:0 [ERROR] FATAL UNHANDLED EXCEPTION: System.Threading.ThreadInterruptedException: Thread interrupted at (wrapper managed-to-native) System.Threading.WaitHandle:WaitOne_internal (System.Threading.WaitHandle,intptr,int,bool) at System.Threading.WaitHandle.WaitOne (Int32 millisecondsTimeout, Boolean exitContext) [0x0] in filename unknown:0 at System.Net.WebAsyncResult.WaitUntilComplete (Int32 timeout, Boolean exitContext) [0x0] in filename unknown:0 at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x0] in filename unknown:0 at System.Net.HttpWebRequest.GetResponse () [0x0] in filename unknown:0 at System.Net.WebClient.GetWebResponse (System.Net.WebRequest request) [0x0] in filename unknown:0 at System.Net.WebClient.ReadAll (System.Net.WebRequest request, System.Object userToken) [0x0] in filename unknown:0 at System.Net.WebClient.DownloadDataCore (System.Uri address, System.Object userToken) [0x0] in filename unknown:0 Rolf Bjarne Kvinge wrote Hi, On Mon, Apr 16, 2012 at 10:45 AM, victoria lt;iminurbase@gt; wrote: Hello list, I'm not sure if this is a Monotouch bug or if we're doing something wrong here. We're trying to use System.Net.WebClient to fetch some data async with a nice optional Cancel this download button for the user - however trying to cancel the request blows up everything. Behold: Can you be a bit more specific than blows up everything? Is an exception thrown? Is anything printed to the application output / console? Any crash reports? Rolf // random somewhat big file to not download string file = http://www.kernel.org/pub/linux/kernel/v2.0/linux-2.0.1.tar.bz2;; WebClient client = new WebClient(); client.DownloadDataAsync(new Uri(file)); client.CancelAsync(); // kaboom The code above works just fine on .NET/Windows - also, changing DownloadDataAsync to DownloadStringAsync seems to work as we would expect it to (no kaboom, but we need the raw data so unfortunately we can't use it) Thoughts? Bug? Help? / V -- View this message in context: http://monotouch.2284126.n4.nabble.com/CancelAsync-on-DownloadDataAsync-crashes-monotouch-tp4560900p4560900.html Sent from the MonoTouch mailing list archive at Nabble.com. ___ MonoTouch mailing list MonoTouch@.ximian http://lists.ximian.com/mailman/listinfo/monotouch ___ MonoTouch mailing list MonoTouch@.ximian http://lists.ximian.com/mailman/listinfo/monotouch -- View this message in context: http://monotouch.2284126.n4.nabble.com/CancelAsync-on-DownloadDataAsync-crashes-monotouch-tp4560900p4561577.html Sent from the MonoTouch mailing list archive at Nabble.com. ___ MonoTouch mailing list MonoTouch@lists.ximian.com http://lists.ximian.com/mailman/listinfo/monotouch
Re: [MonoTouch] Subscribing to ScrollAnimationEnded on a uitableview has strange results?
Okay, thanks! That makes sense - but it also makes for some really unexpected behaviour that doesn't show until runtime - and if you're not aware of it, it can take quite some time to nail what's happening. (I'm not saying it's bad design, but an exception or warning or SOMETHING would have saved many work hours yesterday! ;-) While I'm really having a hard time accepting the hack of saving the Source and re-set it in the handler, it does seem to work and I'll just pray we don't have to subscribe to the ScrollAnimationEnded again for this project. Maybe next time we can go with Monotouch.Dialog and not implement a custom hack of a pull-to-refresh feature ourselves, which is what ScrollAnimationEnded was needed for. Thanks again, / V -- View this message in context: http://monotouch.2284126.n4.nabble.com/Subscribing-to-ScrollAnimationEnded-on-a-uitableview-has-strange-results-tp4451815p4452926.html Sent from the MonoTouch mailing list archive at Nabble.com. ___ MonoTouch mailing list MonoTouch@lists.ximian.com http://lists.ximian.com/mailman/listinfo/monotouch
[MonoTouch] Subscribing to ScrollAnimationEnded on a uitableview has strange results?
Hello list, hope you can shed some light on this odd issue we're having. Today I helped track down a really obscure bug. What it came down to is this: deep in the code an uitableview had its ScrollAnimationEnded subscribed to, and when that happened the uitableview.Source for some reason got set to null. I think the best way I can explain it is with a simple test case: --- class DoNothing : UITableViewSource { public override int RowsInSection (UITableView tableview, int section) { return 0; } public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath) { return new UITableViewCell(); } } public override void ViewDidLoad () { UITableView tableview = new UITableView(); tableview.Source = new DoNothing(); Console.WriteLine(source null? + (tableview.Source == null)); // false tableview.ScrollAnimationEnded += (s, e) = { }; Console.WriteLine(source null? + (tableview.Source == null)); // true, what happened here? } --- we worked around the problem by saving the uitableview.source just before subscribing to the event, then in the event handler we simply set the source again. This seem to work and luckily we don't really need the source until the event has fired, but I can't for my life understand WHY .source is cleared on subscribing to the event, or what else happens that we haven't noticed yet (hint: this is the real question that worries me). This by the way, doesn't work either: var tmp = tableview.Source; tableview.ScrollAnimationEnded += (s, e) = { }; tableview.Source = tmp; Because setting Source to tmp clears the subscribed event. Is this really expected behavior, are we missing something? Or maybe, what is the proper way to subscribe to ScrollAnimationEnded without strange side effects? / V -- View this message in context: http://monotouch.2284126.n4.nabble.com/Subscribing-to-ScrollAnimationEnded-on-a-uitableview-has-strange-results-tp4451815p4451815.html Sent from the MonoTouch mailing list archive at Nabble.com. ___ MonoTouch mailing list MonoTouch@lists.ximian.com http://lists.ximian.com/mailman/listinfo/monotouch
[MonoTouch] Backgroundtworker or new Thread
Hi list! I have two working solutions here and I'm wondering which I should go with. I'm firing off a thread in the background to do some heavy lifting and at first I use new Thread() and ran it like so: var thread = new Thread(Load); thread.IsBackground = true; // Might not be needed? I don't remember thread.Start(); public Load() { using(var pool = new NSAutoreleasePool()) { doStuff(); InvokeOnMainThread(() = { done(); } } } Now, while that works fine, I really like BackgroundWorker because threads are scary, so I ran with this instead: BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += (sender, e) = { doStuff(); } bw.RunWorkerAsync(); bw.RunWorkerCompleted += (sender, e) = { InvokeOnMainThread(() = { done(); } } QUESTIONS: Are both methods above 100% equivalent, or is one better than the other when it comes to Monotouch? Do I still need to wrap the content of the backgroundworker anonymous method in a NSAutoreleasePool? Any input on this would be much appreciated! / Victoria -- View this message in context: http://monotouch.2284126.n4.nabble.com/Backgroundtworker-or-new-Thread-tp4285091p4285091.html Sent from the MonoTouch mailing list archive at Nabble.com. ___ MonoTouch mailing list MonoTouch@lists.ximian.com http://lists.ximian.com/mailman/listinfo/monotouch
[MonoTouch] Using images instead of text labels on bars with CorePlot
Hello! Like many, I'm fairly new to MonoTouch but have a history with both Mono and .NET. So far, we're getting along fine - until now. I've spent literally the whole weekend with one simple goal; to change the BarPlot.cs sample application from the CorePlotiOSSample to use images (think icons) on top of the bars instead of text labels saying bar 0, bar 1, and so on. From the objc examples I've found it looks like this should be possible, and fairly simple by using CPTPlotSpaceAnnotation. But, I can't for the life of me get it to work with MonoTouch. Question: Have anyone done this in MonoTouch before and have just a few lines of sample code to share, or at least can point me in the right direction? Or is this just not possible with the MonoTouch bindings (during my trials and errors there have been a few times when the icons simply don't seem to display anywhere)? The closest thing I've gotten to work is to manually place images on top of the bars by hardcoding their X/Y positions. Any help here would be greatly appreciated. / Victoria -- View this message in context: http://monotouch.2284126.n4.nabble.com/Using-images-instead-of-text-labels-on-bars-with-CorePlot-tp3996006p3996006.html Sent from the MonoTouch mailing list archive at Nabble.com. ___ MonoTouch mailing list MonoTouch@lists.ximian.com http://lists.ximian.com/mailman/listinfo/monotouch