UIActivityIndicatorView/detachNewThreadSelector - uiactivityindicatorview

I am using UIActivityIndicatorView for the first time in an iPhone app, in order to let the user know that some process is on the way.
To do that I use the detachNewThreadSelector method (also for the first time).
I end up with code like this:
[myActivityIndicator startAnimating];
[NSThread detachNewThreadSelector:#selector(theWorkToBeDone:) toTarget:self withObject:myObject];
The problem is that when I time the application. It takes about 5 times longer to perform the task when I use the code above than when I do not use UIActivityIndicatorView and detachNewThreadSelector. (In which case the user still waits, but a shorter time).
Is this difference in timing what I should expect when using UIActivityIndicatorView ?
Or am I making some beginner mistake due to my inexperience with both UIActivityIndicatorView and detachNewThreadSelector?
Thanks for any bit of information.

I just found out that adding this line a the beginning of the theWorkToBeDone method:
NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];
and this one at the end:
[pool release];
solves my problem.

Related

'ChromiumWebBrowser' does not contain a definition for 'NewScreenshot'

I'm just looking into CefSharp and am confused about NewScreenshot. I've found lots of references to it as well as example code, but none of it works. I found it marked as obsolete in the 63.0 docs...
Has NewScreenshot been removed? If so, what replaces it (how can I tell that the screen has rendered)? For my purposes a blocking (non-async) method would work fine.
Update:
Searching the source for the latest version of CefSharp I find no reference to NewScreenshot.
I started with the Minimal Example that #amaitland referred to. I made a few changes, adapting it for my use. As part of that change I moved the Shutdown() call to the program's destructor.
When I ran the project I received a mystifying error about calling Shutdown() from a thread different than the thread from which Initialize() was called.
Looking through the code I saw ScreenshotAsync and, as I wasn't (knowingly) using another thread, suspected it may be involved. I looked for another way to get my SVG image and found NewScreenshot. Which of course didn't solve my problem, which was that the GC was running my destructor in a different thread (I had no idea that could happen).
At any rate, by this time I'd shucked ScreenshotAsync for NewScreenshot which is how I ended up here.
I set a breakpoint in my handler (which I haven't included as it's never called). Here's what I hope is the relevant code. I've omitted the init code but I believe it's unchanged from the example.
public static void Main()
{
private const string url = "https://www.google.com/";
browser = new ChromiumWebBrowser();
browser.Paint += OnBrowserPaint;
browser.Load(url)
Console.ReadKey();
}
In stepping through the code in the debugger, I set a breakpoint on browser.Load(url). If I examine browser.Paint, I find errors:
Here's the tooltip for DeclaringMethod:
I have no idea if this is related to my event handler not firing, but want to point it out in the event it is involved.
I appreciate your other suggestions but feel I need to find out why an event that should be firing is not.
I'll be happy to reduce and upload the project if it will help. Oh, and thanks for your help!

WatchKit without ARC causes crash when dealloc

The watch app I am developing is not using ARC. And so I releases all the properties of objects in each interface in dealloc as below.
-(void)dealloc {
[obj1 release];
[obj2 release];
...
[super dealloc];
}
This causes crash when i close the interface (for example to go back to main interface). Why is this so?
Retains and releases need to be balanced in the context of your class. Probably you didn't retain when you assigned to one of those instance variables, and thus it's an over-release. You can try enabling zombies to catch the message to a deallocated instance if that's the case.

UIImagePickerController takePicture crashes

I have been trying to find out what is causing this crash.
My main view controller has some code like this to start camera picker.
pickerControl = [[UIImagePickerController alloc] init];
pickerControl.sourceType = UIImagePickerControllerSourceTypeCamera;
pickerControl.allowsEditing = NO;
pickerControl.wantsFullScreenLayout = YES;
pickerControl.showsCameraControls = NO;
pickerControl.cameraOverlayView = overlay;
pickerControl.delegate = self;
overlay.delegate = self;
[self presentViewController:pickerControl animated:NO completion:nil];
The overlay is a view with a few buttons at the bottom. one of them is calling back to take picture.. and the call back will call takePicture like below..
[pickerControl takePicture];
I dont know what is causing it, but it crashes immediately after calling takePicture. It doesn't happen all the time.. but it crashes more often.
Please help to understand what is going wrong.
You're asking about beta software that's accessible only after consenting to a non-disclosure agreement. So I'm going to ignore the iOS 7 aspect of the question.
As to getting a crash log, if you already know which method call is crashing then you're not going to get much out of it. But what you can do is use C's signal to install exception handlers for the various exceptions you want to trace.
Upon receiving such an exception, use [NSThread callStackSymbols] to get an array of call stack symbols — a backtrace in effect. You can then hastily write that to disk and, next run, read it back and notify yourself of it accordingly. Services like Crashlytics accumulate them and post them to a server. You could just open an MFMailComposer and send them to yourself as an attachment.
Using the Crashlytics SDK or a similar product directly would allow you to get live, traced crash reports regardless of whether the build has yet been submitted to Apple and without requiring Xcode to do any parsing.

Unable to update table in superview from subview

I am using Xcode 4.3 and am somewhat of a nubbie in Xcode although I have been a programmer for many years.
I have a UIView called First that contains a UITable that gets its contents from files in memory. I then create a subview UIView called Second that makes changes in the data files that should change the contents of the table in First. When I remove Second and return to First, not surprising, the table is not updated. The next time First is loaded from the start, the table reflects the changes that were made.
First contains the method viewDidLoad which is used to load an NSArray from data in files with the data needed by the table. I am able to call viewDidLoad from Second but unless the table is updated from the newly changed NSArray the table will appear as it did before the changes were made.
So my problem is how to call a table method from Second so that the table in First is updated when I remove Second and return to First. I have tried calling the table method that loads the data into the table but have been unsuccessful since I get compile errors. I need to know how to call the table function in a way that will result in the table being updated when I return to first.
At least part of my problem is I don't know how the table update is called since it is not called from viewDidLoad as I might have expected.
Sorry, it is a long winded description of the problem. Much of the rest of the program that I am writing is working and I have been dealing with this issue for several months. I return every few weeks and take another stab at it but no luck so far. I really would appreciate any help you can give that will improve my understanding and fix the problem.
Here is the code after the fix: first (superview) pertinent code
-(void)viewDidLoad {
NSFileManager * fm = [[NSFileManager alloc] init];
NSError* err = nil;
NSPredicate *fltr = [NSPredicate predicateWithFormat:#"self ENDSWITH '.dir'"];
NSArray *array = [fm contentsOfDirectoryAtPath: userFolder error:&err];
self.listData = [array filteredArrayUsingPredicate:fltr];
[self.tableView reloadData]; //This does the updating must make table an IBOutlet as
[super viewDidLoad]; //described in one of the comments by m. Othman
}
Here is the code after the fix: second (subview) pertinent code. This code located
in the method where changes are made that should effect the table display
UIView * start = [self.view superview]; //this line and next two call viewDidLoad in first
UIResponder * nextResponder = [start nextResponder];
[nextResponder viewDidLoad];
Have you read the UIViewController API reference? There are more options beyond -viewDidLoad for dealing with the (re)appearance of a view...
well, UITableView Delegates called just on the loading of the view or when you ask it to reload ..
so in your viewDidLoad or any method that should changes the content of the tableview , you need to write this line
[tableview reloadData];
I hope I understand your question!!

Flex addEventListener - how to refresh the screen during called event?

I can't seem to find the answer to what I would have thought was a common problem.
What I want to do this is:
1. Show the Open File Dialog
2. Process the file selected
3. During processing the file, report progress to the User
I have a file defined, and am using the browseForOpen and AddEventListener:
public var fileInput:File = new File();
fileInput.browseForOpen("Open file",[filter]);
fileInput.addEventListener(Event.SELECT, onFileSelect);
// Step 2 - function gets called to process the file
private function onFileSelect(e:Event):void
{
// Step 3 - do some processing, and at intervals report progress to the screen
}
My issue is - any changes to the screen within the event listener do not get done until the function is complete.
Any help would be appreciated,
Thanks
Start a timer perhaps and let it check status of a variable(that denotes processing progress) as a separate running function it would not be predisposed to waiting on the parent function.
[ to be clear Im saying call a sperate function from the timer.]
But I am inclined to agree with Flextras.com in that most times I have done this the processing was milliseconds so just didnt get seen.
In Step 3, if you are doing some cpu intensive job(like huge xml parsing), then you might be seeing this NOT updating problem. As Flex is single threaded, you better make use of Green threading concept.
You can read about Green Threading here.

Resources