在mainthread

时间:2016-10-26 07:30:18

标签: ios objective-c

我在clickedButtonAtIndex委托中调用dismissWithClickedButtonIndex,在解雇alertview后我需要调用蓝牙设备[self callDevice]

两者都在主线程中,但[self callDevice]首先执行,然后调用dismissWithClickedButtonIndex。所以alertview需要一段时间才能辞职。

请找到以下代码,

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
     [alertView dismissWithClickedButtonIndex:1 animated:NO];
     [self callDevice];
}

如何首先关闭alertview,然后调用[self callDevice] API? 任何人都可以建议我解决方案吗?

2 个答案:

答案 0 :(得分:0)

实施以下- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex 方法:

UIAlertView

解雇动画完成后将调用此方法。

UIAlertController已弃用。我建议改为使用SELECT DECODE(BOM.ORGANIZATION_ID,203, 'CEC', 328, '3PL', 204, 'SIM') ORGANIZATION_CODE, BOM.ORGANIZATION_ID, MSI.SEGMENT1 "PARENT_ITEM", MSIC.SEGMENT1 "COMPONENT_ITEM", SUM(NVL(MMT.TRANSACTION_QUANTITY,0)) * NVL(SUM(CIC.ITEM_COST),0) "ANNUAL_MONEY", SUM(NVL(MMT.TRANSACTION_QUANTITY,0)) "ANNUAL_QTY_USG", NVL(SUM(CIC.ITEM_COST),0) "AVG_COST", SUM(NVL(MSI.POSTPROCESSING_LEAD_TIME,0) + NVL(MSI.PREPROCESSING_LEAD_TIME,0)) LEAD_TIME FROM BOM_BILL_OF_MATERIALS BOM LEFT JOIN MTL_SYSTEM_ITEMS MSI ON MSI.ORGANIZATION_ID = BOM.ORGANIZATION_ID AND MSI.INVENTORY_ITEM_ID = BOM.ASSEMBLY_ITEM_ID AND MSI.ENABLED_FLAG = 'Y' AND MSI.BOM_ENABLED_FLAG = 'Y' LEFT JOIN CST_ITEM_COSTS CIC ON CIC.ORGANIZATION_ID = BOM.ORGANIZATION_ID AND CIC.INVENTORY_ITEM_ID = BOM.ASSEMBLY_ITEM_ID AND CIC.COST_TYPE_ID = 1 LEFT JOIN MTL_MATERIAL_TRANSACTIONS MMT ON MMT.INVENTORY_ITEM_ID = BOM.ASSEMBLY_ITEM_ID AND MMT.ORGANIZATION_ID = BOM.ORGANIZATION_ID AND MMT.TRANSACTION_TYPE_ID IN (33,34,17) LEFT JOIN MTL_TRANSACTION_TYPES MTT ON MTT.TRANSACTION_TYPE_ID = MTT.TRANSACTION_TYPE_ID LEFT JOIN BOM_INVENTORY_COMPONENTS BIC ON BIC.BILL_SEQUENCE_ID = BOM.COMMON_BILL_SEQUENCE_ID AND NVL(bic.disable_date, sysdate+1) > sysdate LEFT JOIN BOM_COMPONENTS_B BCB ON BIC.COMPONENT_SEQUENCE_ID = BCB.COMPONENT_SEQUENCE_ID LEFT JOIN BOM_STRUCTURES_B BSB ON BCB.BILL_SEQUENCE_ID = BSB.BILL_SEQUENCE_ID LEFT JOIN MFG_LOOKUPS ML ON ML.LOOKUP_CODE = BIC.WIP_SUPPLY_TYPE AND ML.LOOKUP_CODE = BIC.ENFORCE_INT_REQUIREMENTS AND ML.LOOKUP_TYPE = 'MTL_EAM_ITEM_TYPE' LEFT JOIN MTL_SYSTEM_ITEMS MSIC ON MSIC.ORGANIZATION_ID = BOM.ORGANIZATION_ID AND MSIC.INVENTORY_ITEM_ID = BIC.COMPONENT_ITEM_ID LEFT JOIN BOM_OPERATIONAL_ROUTINGS BOR ON BOR.ASSEMBLY_ITEM_ID = BOM.ASSEMBLY_ITEM_ID AND BOR.ORGANIZATION_ID = BOM.ORGANIZATION_ID WHERE BOM.ORGANIZATION_ID = NVL(:P_ORG_ID,BOM.ORGANIZATION_ID) AND EXISTS (SELECT 'X' FROM MTL_MATERIAL_TRANSACTIONS MMT WHERE MMT.TRANSACTION_DATE >= ADD_MONTHS (SYSDATE,-12) AND MSI.INVENTORY_ITEM_ID IS NOT NULL ) GROUP BY BOM.ORGANIZATION_ID, MSI.SEGMENT1, MSIC.SEGMENT1 ORDER BY ORGANIZATION_CODE, MSIC.SEGMENT1

答案 1 :(得分:0)

使用UIAlertView委托方法didDismissWithButtonIndex,该方法将在UIAlertView被解雇后调用。

使用didDismissWithButtonIndex,如下所示:

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{

    if(buttonIndex==1){

        //UIAlertView is dismissed by clicking button at index 1, now call your method

        [self callDevice];

    }

}

注意: UIAlertView已弃用,而是使用UIAlertController