Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6125915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:18:17+00:00 2026-05-23T16:18:17+00:00

Possible Duplicate: Make UIAlertView blocking Been beating my head against the wall for hours

  • 0

Possible Duplicate:
Make UIAlertView blocking

Been beating my head against the wall for hours on this one.

Here’s what I’ve got: OrderDetailsViewController is set as an UIAlertViewDelegate

I’ve got a procedure that receives information back from a search form. It checks to see if the item is already on the order and if not continues adding the item(s). If it sees a duplicate, it pops up a UIAlertView asking what the user wants to do: there are 3 options, “Combine” – add the new qty to the old item, “Add” the duplicate as a separate line item, or “Cancel” throw the new item away. I need it to wait for an answer from the UIAlertView so that I can continue adding the dupe or throwing away the dupe — the “Combine” is handled in the delegate, but I still need an answer for the main procedure.

Here’s what I have so far:

 - (void)returnItemAndQty:(ProductsSearchController *)productsSearchController
         withItemsToAdd:(NSMutableArray *)itemsToAdd 
         withQty:(NSDictionary *)qtyToAdd andClose:(BOOL)close
{
if ([itemsToAdd count] == 0) {
    return;
}
Items *items;
for (int index = 0; index < [itemsToAdd count]; index++) {
    items = [itemsToAdd objectAtIndex:index];
    qtyAddedToOrder = [NSDecimalNumber decimalNumberWithString:[qtyToAdd objectForKey:items.ItemCode]];     
    NSLog(@"Item Code: %@", items.ItemCode);
    NSLog(@"Qty: %@", [qtyToAdd objectForKey:items.ItemCode]);
    NSError *error;

    //For handling duplicate items. . . 
    duplicateItemDisposition = -1; //Reset the dispostion for normal operation
    if([self isItemOnOrder:items.ItemCode])
    {
        int i = [self itemIsAlreadyOnOrder:itemAlreadyOnOrder withQty:qtyAddedToOrder];

        if (i == COMBINE || i == CANCEL){ //either Cancel or Combine was pressed.
            items.Checked = NO;
            if (![items.managedObjectContext save:&error])
            {
                NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
            }
            continue;
        }
    }
    //Add the new item or duplicate if that's what you want
    OrdersDetails *newOrderDetail = [NSEntityDescription insertNewObjectForEntityForName:@"OrdersDetails" 
                                                                  inManagedObjectContext:self.managedObjectContext];

.//more code snipped, that handles the "ADD" or non-dupe
.
.

Here’s where it tests for a duplicate. . .

- (BOOL)isItemOnOrder:(NSString *)itemCode
{

 NSFetchRequest *request = [[NSFetchRequest alloc] init];

     NSEntityDescription *entity = [NSEntityDescription entityForName:@"OrdersDetails"
                                          inManagedObjectContext:managedObjectContext];
    [request setEntity:entity];

    NSSortDescriptor *sort = [[NSSortDescriptor alloc]initWithKey:@"Desc1" ascending:NO];
    NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sort, nil];
    [request setSortDescriptors:sortDescriptors];
    [sort release];
    [sortDescriptors release];

    NSPredicate *pred = [NSPredicate predicateWithFormat:@"(ItemCode=%@ AND OrderID=%@)", itemCode, orders.OrderID];
    [request setPredicate:pred];

    NSError *error;
    NSMutableArray *mutableFetchResults = [[managedObjectContext executeFetchRequest:request error:& error] mutableCopy];
   [request release];
   if (mutableFetchResults == nil) {
       itemAlreadyOnOrder = nil;
       return NO;
   }else if ([mutableFetchResults count] > 0){
       itemAlreadyOnOrder = [mutableFetchResults objectAtIndex:0];
       return YES;
   }else{
       itemAlreadyOnOrder = nil;
       return NO;
   }
}

Here’s where it sees that a dupe exists and the UIAlertview delegate with it. . .

- (int) itemIsAlreadyOnOrder:(OrdersDetails *)existingOrderDetail withQty:(NSDecimalNumber *)qty 
{
    if (existingOrderDetail == nil) {
    return -1;
    }

    UIAlertView *duplicateAlert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"Duplicate Item %@ found.",existingOrderDetail.ItemCode] message:@"Tap Combine to combine the items, Tap Add to add the duplicate item or Tap Cancel to discard the duplicate" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Combine", @"Add", nil];
    [duplicateAlert show];

    return duplicateItemDisposition;

    [duplicateAlert release];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
// Cancel = 0, Combine = 1, Add = 2

    if (buttonIndex == CANCEL){
        duplicateItemDisposition = CANCEL;
    }else if (buttonIndex == COMBINE){
            duplicateItemDisposition = COMBINE;
            NSDecimalNumber *existingQty = [[NSDecimalNumber alloc] initWithDecimal:[itemAlreadyOnOrder.Qty decimalValue]];
            NSDecimalNumber *existingPrice = itemAlreadyOnOrder.Price;
            NSDecimalNumber *newQty = [existingQty decimalNumberByAdding:qtyAddedToOrder];
            itemAlreadyOnOrder.ExtPrice = [newQty decimalNumberByMultiplyingBy:existingPrice];
           [existingQty release];
           NSError *error;
           if (![itemAlreadyOnOrder.managedObjectContext save:&error]){
        NSLog(@"Error saving. %@, %@", error, [error userInfo]);
               [self handleFreeGoods:itemAlreadyOnOrder];
           }else if (buttonIndex == ADD){
               duplicateItemDisposition = ADD;
           }
}

Now I read something on here about using an NSCondition in a background thread, but I have no idea what that means. I looked up NSCondition, and it was less than enlightening.

Any ideas on how to pause the execution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:18:18+00:00Added an answer on May 23, 2026 at 4:18 pm

    The UIAlertView can’t block, as it gets displayed at the end of the runloop. Instead of having the method itemIsAlreadyOnOrder: return a value indicating what should be done with the duplicate entry, the delegate method from the UIAlertView needs to notify your controller that the item in question has been resolved. Track the object in question somewhere (_objectToVerify or something like that), and in the delegate method from the UIAlertView call a method based on the users choice, which will act on that _objectToVerify.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How to horizontally center a div? One simple way to make an
Possible Duplicate: How to make drag-and-drop from one list to another in C#/WindowsForms? I
Possible Duplicate: RegEx to make sure that the string contains at least one lower
Possible Duplicate: UITextField in UIAlertView on iPhone - how to make it responsive? UITextField
Possible Duplicate: How can I make this query to accept dynamic table names? I
Possible Duplicate: Make iPhone app paid version replace free version on install from app
Possible Duplicate: Complex CSS selector for parent of active child How would I make
Duplicate: Run .NET exe in linux Hello, Is it possible to make my existing
Possible Duplicate: NAnt or MSBuild, which one to choose and when? What is the
Possible Duplicate: How do I calculate someone's age in C#? Maybe this could be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.