Re: Display a UIAlertView after dismissing an action sheet?

2015-04-25 Thread Mike Abdullah

> On 25 Apr 2015, at 15:30, Michael Crawford  wrote:
> 
> On 4/25/15, Mike Abdullah  wrote:
>> Apple's APIs here are deliberately asynchronous. You need to make your code
>> handle that properly. Don't try to force it to be synchronous.
> 
> Some things need to be synchronous though.  If I'm saving a file, I
> don't want to do anything else unless the file is saved, or perhaps
> the operation is cancelled by the user.

You’ve kind of answered your own questioning there.

UIAlertView provides a modal UI; the user can’t do anything else while it’s 
displayed. So you don’t need to force your code to be synchronous. Take the 
asynchronous code Apple gives you and run with it.

> 
> What's your take on the following?  I found the bit with the runloop
> at stackoverflow.
> 
> + (NSString*) copyFileName: (NSString*) question
>withTextPrompt: (NSString*) prompt
> {
>ModalAlertDelegate *delegate = [[ModalAlertDelegate alloc] init];
> 
>assert( nil != delegate );
>assert( 1 == [delegate retainCount] );
> 
>UIAlertView *alertView = [[UIAlertView alloc] initWithTitle: question
>message: @"Untitled"
>   delegate: delegate
>  cancelButtonTitle: @"Cancel"
>  otherButtonTitles: @"OK", nil];
>alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
> 
>assert( 1 == [alertView retainCount] );
>assert( 1 == [delegate retainCount] );

Don’t do this. Absolute retain counts are none of your business. Have you 
considered adopting ARC? It would likely make your life a lot easier.
> 
>[alertView show];
> 
>while( [alertView isVisible] ){
>NSRunLoop *rl = [NSRunLoop currentRunLoop];
>NSDate *today = [[NSDate alloc] init];
> 
>[rl runUntilDate: today];
>[today release];
> 
>}

Don’t do this. There is no need to make the API behave synchronously. Make your 
code asynchronous instead.
> 
>[alertView release];
> 
>NSString *result = [delegate.text copy];
> 
>[delegate release];
> 
>return result;
> } 
> 
> delegate.text is copied from the UIAlertView's text field in the
> delegate's buttonClickedAtIndex method.
> 
> I don't yet have a way to report that the user cancelled but that will
> be simple to add.  This seems to work as far as it goes.
> 
> -- 
> Michael David Crawford, Consulting Software Engineer
> mdcrawf...@gmail.com
> http://www.warplife.com/mdc/
> 
>   Available for Software Development in the Portland, Oregon Metropolitan
> Area.
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/mabdullah%40karelia.com
> 
> This email sent to mabdul...@karelia.com


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Display a UIAlertView after dismissing an action sheet?

2015-04-25 Thread Roland King

> On 25 Apr 2015, at 21:30, Michael Crawford  wrote:
> 
> On 4/25/15, Mike Abdullah  wrote:
>> Apple's APIs here are deliberately asynchronous. You need to make your code
>> handle that properly. Don't try to force it to be synchronous.
> 
> Some things need to be synchronous though.  If I'm saving a file, I
> don't want to do anything else unless the file is saved, or perhaps
> the operation is cancelled by the user.

There are always ways to use asynchronous APIs to appear to be synchronous. 

> 
> What's your take on the following?  I found the bit with the runloop
> at stackoverflow.
> 

….

> 
>while( [alertView isVisible] ){
>NSRunLoop *rl = [NSRunLoop currentRunLoop];
>NSDate *today = [[NSDate alloc] init];
> 
>[rl runUntilDate: today];
>[today release];
> 
>}

yeah that’s the sort of hacky bad code I see on StackOverflow all the time. 
Running runloops inside the main runloop, not a good idea, Might work today, 
might not work tomorrow. The main runloop does lots more than it used to, 
integrates with the main dispatch queue, who knows what else. Running nested 
runloops to pretend force synchronous isn’t something I’d do. 
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Display a UIAlertView after dismissing an action sheet?

2015-04-25 Thread Michael Crawford
On 4/25/15, Mike Abdullah  wrote:
> Apple's APIs here are deliberately asynchronous. You need to make your code
> handle that properly. Don't try to force it to be synchronous.

Some things need to be synchronous though.  If I'm saving a file, I
don't want to do anything else unless the file is saved, or perhaps
the operation is cancelled by the user.

What's your take on the following?  I found the bit with the runloop
at stackoverflow.

+ (NSString*) copyFileName: (NSString*) question
withTextPrompt: (NSString*) prompt
{
ModalAlertDelegate *delegate = [[ModalAlertDelegate alloc] init];

assert( nil != delegate );
assert( 1 == [delegate retainCount] );

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle: question
message: @"Untitled"
   delegate: delegate
  cancelButtonTitle: @"Cancel"
  otherButtonTitles: @"OK", nil];
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;

assert( 1 == [alertView retainCount] );
assert( 1 == [delegate retainCount] );

[alertView show];

while( [alertView isVisible] ){
NSRunLoop *rl = [NSRunLoop currentRunLoop];
NSDate *today = [[NSDate alloc] init];

[rl runUntilDate: today];
[today release];

}

[alertView release];

NSString *result = [delegate.text copy];

[delegate release];

return result;
}   

delegate.text is copied from the UIAlertView's text field in the
delegate's buttonClickedAtIndex method.

I don't yet have a way to report that the user cancelled but that will
be simple to add.  This seems to work as far as it goes.

-- 
Michael David Crawford, Consulting Software Engineer
mdcrawf...@gmail.com
http://www.warplife.com/mdc/

   Available for Software Development in the Portland, Oregon Metropolitan
Area.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Display a UIAlertView after dismissing an action sheet?

2015-04-25 Thread Mike Abdullah

> On 25 Apr 2015, at 15:06, Michael Crawford  wrote:
> 
> On 4/25/15, Roland King  wrote:
>> There are delegate methods for UIActionSheet and UIAlertView which tell you
>> when the animation has finished.
>> 
>> xxx:didDismissWithButtonIndex:
> 
> You Da Man.
> 
> I am closer to understanding why this is not working.
> 
> my call to "[alertView show]" returns immediately.  At some later
> point the UIAlertView actually appears on screen.  If I then tap a
> button, the UIAlertViewDelegate's clickedButtonAtIndex method is
> called.
> 
> However the logic I presently have in my code is:
> 
>   NSString baseName = [ModalAlertView copyFilename];
> 
> where copyFilename is a class method.  If it calls [alertView show],
> which returns immediately then I need a way to wait around until the
> button is clicked.  At that point I check for an existing file and
> potentially show another alert - without a text field - to ask whether
> they want to overwrite an existing file.
> 
> I expect I can work out logic that will accomplish what I need but
> this must be a common problem, can anyone suggest a solution to this?
> 
> Another way to put it is that I want to prompt for a filename, and
> verify any overwrite, in a synchronous manner.

Apple’s APIs here are deliberately asynchronous. You need to make your code 
handle that properly. Don’t try to force it to be synchronous.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Display a UIAlertView after dismissing an action sheet?

2015-04-25 Thread Michael Crawford
On 4/25/15, Roland King  wrote:
> There are delegate methods for UIActionSheet and UIAlertView which tell you
> when the animation has finished.
>
> xxx:didDismissWithButtonIndex:

You Da Man.

I am closer to understanding why this is not working.

my call to "[alertView show]" returns immediately.  At some later
point the UIAlertView actually appears on screen.  If I then tap a
button, the UIAlertViewDelegate's clickedButtonAtIndex method is
called.

However the logic I presently have in my code is:

   NSString baseName = [ModalAlertView copyFilename];

where copyFilename is a class method.  If it calls [alertView show],
which returns immediately then I need a way to wait around until the
button is clicked.  At that point I check for an existing file and
potentially show another alert - without a text field - to ask whether
they want to overwrite an existing file.

I expect I can work out logic that will accomplish what I need but
this must be a common problem, can anyone suggest a solution to this?

Another way to put it is that I want to prompt for a filename, and
verify any overwrite, in a synchronous manner.

-- 
Michael David Crawford, Consulting Software Engineer
mdcrawf...@gmail.com
http://www.warplife.com/mdc/

   Available for Software Development in the Portland, Oregon Metropolitan
Area.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Display a UIAlertView after dismissing an action sheet?

2015-04-25 Thread Roland King
> 
> I think the problem is that I need to be certain that the action sheet
> is all the way dismissed before I show the alert.  I think that's what
> all the stuff about runloops was in my previous question, that didn't
> make sense to anyone.  I got that from Erica Sadun's "iPhone
> Developer's Cookbook”.
> 

There are delegate methods for UIActionSheet and UIAlertView which tell you 
when the animation has finished. 

xxx:didDismissWithButtonIndex:



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Display a UIAlertView after dismissing an action sheet?

2015-04-25 Thread Michael Crawford
I was running on an iPad.  When I switched to the iPad 2 simulator, I
could enable Guard Malloc.

With guard malloc an assert is tripped over a retain count that, at
that point, should be 1.

I expect I have an errant pointer elsewhere in my code.  I know how to
track such things down.

I'm not dead certain yet but something like this may ultimately work:

- (IBAction) doSave
{
   [self performSelector: delayedSave withObject: nil afterDelay: 2.0];
}

- (void) delayedSave: (id) object
{
   // prompt for file name with UIAlertView, then save the file
}

What I would prefer would be to have a guarantee that the action sheet
has already been dismissed before I display the alert.  Just trying
out different ad-hoc delays seems a little sketchy.

On 4/25/15, Michael Crawford  wrote:
> My iOS App includes some simple file management, that enables the user
> to save the state of their game as well as to exchange the game states
> with other people.
>
> I have a sheet that looks like this:
>
>Title: File Management
>Destructive Option: Delete File
>Open
>Save
>
> I also specify a "Cancel" item which does not display on the iPad, as
> the user can cancel by tapping outside.
>
> When they tap Save I want to prompt the user for a filename with
> UIAlertView.  This is where my question came up before, regarding that
> alert having zero size.  I'm using the newer API now, with the style
> that prompts for text.
>
> If I do it in a straightforward way the alert is not displayed.
>
> If I called "usleep( 150 )" the alert is briefly displayed then
> dismissed.
>
> My delegate's "clickedButtonAtIndex" method is never called.
>
> I think the problem is that I need to be certain that the action sheet
> is all the way dismissed before I show the alert.  I think that's what
> all the stuff about runloops was in my previous question, that didn't
> make sense to anyone.  I got that from Erica Sadun's "iPhone
> Developer's Cookbook".
>
> I expect what's happening is that the user taps "Save" in the action
> sheet, then the iOS calls my "doSave" IBAction, then ultimately from
> doSave, the alertview is displayed.  That leads to the instantiation
> of the alertview being - indirectly - a subroutine of the action
> sheet.
>
> Maybe it would work if doSave called NSObject's "performSelector" I'll
> give that a try while I eagerly await your responses.
>
> Mike
> --
> Michael David Crawford, Consulting Software Engineer
> mdcrawf...@gmail.com
> http://www.warplife.com/mdc/
>
>Available for Software Development in the Portland, Oregon Metropolitan
> Area.
>


-- 
Michael David Crawford, Consulting Software Engineer
mdcrawf...@gmail.com
http://www.warplife.com/mdc/

   Available for Software Development in the Portland, Oregon Metropolitan
Area.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Display a UIAlertView after dismissing an action sheet?

2015-04-25 Thread Michael Crawford
My iOS App includes some simple file management, that enables the user
to save the state of their game as well as to exchange the game states
with other people.

I have a sheet that looks like this:

   Title: File Management
   Destructive Option: Delete File
   Open
   Save

I also specify a "Cancel" item which does not display on the iPad, as
the user can cancel by tapping outside.

When they tap Save I want to prompt the user for a filename with
UIAlertView.  This is where my question came up before, regarding that
alert having zero size.  I'm using the newer API now, with the style
that prompts for text.

If I do it in a straightforward way the alert is not displayed.

If I called "usleep( 150 )" the alert is briefly displayed then dismissed.

My delegate's "clickedButtonAtIndex" method is never called.

I think the problem is that I need to be certain that the action sheet
is all the way dismissed before I show the alert.  I think that's what
all the stuff about runloops was in my previous question, that didn't
make sense to anyone.  I got that from Erica Sadun's "iPhone
Developer's Cookbook".

I expect what's happening is that the user taps "Save" in the action
sheet, then the iOS calls my "doSave" IBAction, then ultimately from
doSave, the alertview is displayed.  That leads to the instantiation
of the alertview being - indirectly - a subroutine of the action
sheet.

Maybe it would work if doSave called NSObject's "performSelector" I'll
give that a try while I eagerly await your responses.

Mike
-- 
Michael David Crawford, Consulting Software Engineer
mdcrawf...@gmail.com
http://www.warplife.com/mdc/

   Available for Software Development in the Portland, Oregon Metropolitan
Area.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com