ios - 我有一个 UIAlertView 反复显示找不到源的问题

标签 ios objective-c xcode uialertview

我的问题是,在应用程序中,当用户单击某个不重要的地方时,会引发 alertView,没关系,我可以找到对该 View 的调用,但随后一次又一次地显示为空,我在我看到的任何地方都放置了断点调用任何警报。但是幽灵警报并没有在任何地方中断,我不知道是谁扔的,这只是一种有意识的观点。

您能否就如何确定调用 View 的位置提供一些提示?

Phantom alertView

Breakpoint never hitting that alert

编辑:

viewController 代码:

#import <CoreLocation/CoreLocation.h>
#import "FormViewController.h"
#import "FormPageViewController.h"
#import "FormElement+UtilityMethods.h"
#import "UserBO.h"
#import "RecordBO.h"
#import "RecordAnswer.h"
#import "UserDefaultsUtilities.h"
#import "TimeTrackingUtilities.h"
#import "DxColors.h"
#import "EDQueueUtilities.h"
#import "GroupAnswerMetadata.h"
#import "RecordAnswer+UtilityMethods.h"
#import "Record+UtilityMethods.h"
#import "FormPageIndexViewController.h"
#import "ManagedObjectUtilities.h"
#import "EDQueue.h"
#import "EDQueueUtilities.h"
#import "DxAnswerObject.h"
#import "ImageAnswerMetadata.h"

#import "DateUtilities.h"
#import <ifaddrs.h>
#import "CarbonKit.h"

#define INITIAL_CONTROLLER_INDEX 0
#define FORM_RECORDS_TEMP_NAME @"<~TMP>"

#define TAG_RETURN_BUTTON 0
#define TAG_SAVE_BUTTON 1
#define TAG_SEND_BUTTON 2

typedef NS_ENUM(NSUInteger, AlertViewPurpose) {
    ALERT_VIEW_FORM_NONE                = 0,
    ALERT_VIEW_FORM_SEND_SUCCESS        = 1,
    ALERT_VIEW_FORM_SEND_FAILURE        = 2,
    ALERT_VIEW_FORM_SAVE_PROMPT         = 3,
    ALERT_VIEW_FORM_FILE_NAME_PROMPT    = 4,
    ALERT_VIEW_FORM_ASYNC_SEND_SUCCESS  = 5,
    ALERT_VIEW_FORM_COULDNT_SEND        = 6,
    ALERT_VIEW_FORM_WANT_TO_SEND        = 7,
    ALERT_VIEW_FORM_SAVE_IN_CONTEXT_PROMPT = 8,
    ALERT_VIEW_FORM_FILE_NAME_IN_CTXT_SAVE_PROMPT = 9,
    ALERT_VIEW_FORM_REQUIRED_INTERNET_CONECTION = 10,
    // Enumeration counter.
    ALERT_VIEW_PURPOSE_COUNT
};

// Based on:
// Ref.: http://www.appcoda.com/uipageviewcontroller-storyboard-tutorial/

@interface FormViewController () <RecordBOProtocol, FieldElementProtocol,
CLLocationManagerDelegate, FormPageIndexProtocol,CarbonTabSwipeNavigationDelegate>
{
    AlertViewPurpose _currentAlertViewPurpose;
    CarbonTabSwipeNavigation *_carbonTabSwipeNavigation;
    BOOL _unedited;
    BOOL _formRecordNilAtStartUp;
    BOOL _timestampTaken;

    CLLocationManager *_locationManager;
    CLLocation *_location;
    NSDate *_timeSpentBaseTimestamp;
    NSArray *_sortedPages;
    NSUInteger _currentPageIndex;
    NSString *formID;
    NSArray *_pagesNames;
}

@property (weak, nonatomic) IBOutlet UILabel *lblFormTitle;
@property (weak, nonatomic) IBOutlet UIButton *btnSmallReturn;
@property (weak, nonatomic) IBOutlet UIButton *btnSmallSave;
@property (weak, nonatomic) IBOutlet UIButton *btnSmallSend;
@property (weak, nonatomic) IBOutlet UIButton *btnBigSend;

@property (weak, nonatomic) IBOutlet UIBarButtonItem *btnReturn;

@property (strong, nonatomic) IBOutlet UIButton *lblBack;
@property (strong, nonatomic) IBOutlet UIButton *lblSave;


@end

@implementation FormViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        _currentAlertViewPurpose = ALERT_VIEW_FORM_NONE;
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    [self localizedButtons];

    // Starting up location manager if form requires it.
    // Ref.:
    // https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/index.html#//apple_ref/occ/instm/CLLocationManager/requestAlwaysAuthorization
    if ([self.form.geolocationEnabled boolValue]) {

        _locationManager = [[CLLocationManager alloc] init];
        _locationManager.delegate = self;

        if ([CLLocationManager locationServicesEnabled]) {

            CLAuthorizationStatus status = [CLLocationManager authorizationStatus];

            if (status == kCLAuthorizationStatusNotDetermined) {
                // Requesting authorization.
                if ([CLLocationManager instancesRespondToSelector:@selector(requestWhenInUseAuthorization)]) {
#ifdef DEBUG_MODE
                    NSAssert(
                             [[[NSBundle mainBundle] infoDictionary] valueForKey:@"NSLocationWhenInUseUsageDescription"],
                             @"For iOS 8 and above, your app must have a value for NSLocationWhenInUseUsageDescription in its Info.plist");
#endif // DEBUG_MODE
                    [_locationManager requestWhenInUseAuthorization];
                }
            } else if (status == kCLAuthorizationStatusAuthorizedAlways ||
                       status == kCLAuthorizationStatusAuthorizedWhenInUse) {
                _locationManager.distanceFilter = kCLDistanceFilterNone;
                _locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
                [_locationManager startUpdatingLocation];
            }
        }
    }

    self.lblFormTitle.text = self.form.name ;

    // Saving whether self.formRecord was nil at beginning.
    // Important for time spent tap calculations.
    _formRecordNilAtStartUp = self.formRecord == nil;

    [self setup];

    //Take the time for counting 
    _timeSpentBaseTimestamp = [NSDate date];

    _unedited = YES;
}

-(void)localizedButtons
{
    [self.lblBack setTitle:NSLocalizedString(@"Back", @"Regresar") forState:UIControlStateNormal];
    [self.lblSave setTitle:NSLocalizedString(@"Save", @"Guardar") forState:UIControlStateNormal];
    [self.btnBigSend setTitle:NSLocalizedString(@"Send", @"Enviar") forState:UIControlStateNormal];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

// Overriding from DxBaseViewController.
-(void)refresh
{
}

-(void)setup
{
    // Obtaining sorted pages array.
    _sortedPages = [[self.form.pages allObjects]
                    sortedArrayUsingComparator:^NSComparisonResult(Page *obj1, Page * obj2) {
                        return [obj1.pageNumber compare: obj2.pageNumber];
                    }];
    //Adding toolBar
    NSMutableArray *namesPages = [[NSMutableArray alloc]init];

    for (Page *page in _sortedPages) {
        NSString *namePage = page.name;
        [namesPages addObject:namePage];
    }
    _pagesNames = [namesPages copy] ;

    // Creating by default a record in case there's none.
    if (self.formRecord == nil) {
        self.formRecord = [Record createInContext:self.managedObjectContext];
        // Filling in basic record information.
        self.formRecord.name = FORM_RECORDS_TEMP_NAME;
        self.formRecord.editable = self.form.editableRecords;
        self.formRecord.dateLastSaved = self.formRecord.dateCreated = [NSDate date];
        self.formRecord.syncStatusId = [NSNumber numberWithInt:SYNC_STATUS_NOT_SYNCED];
        self.formRecord.user = [UserBO loggedInUser];
        self.formRecord.form = self.form;
        self.formRecord.formId = self.form.pkey;
        self.formRecord.temporary = [NSNumber numberWithBool:YES];
        self.formRecord.isBeingEdited = [NSNumber numberWithBool:YES];
        // Committing record information as is. It will be removed if user doesn't
        // want to save changes.
        if (![Record commitChangesFromContext:self.managedObjectContext]) {
            DebugLog(@"Temp form record couldn't be saved! Check!");
        }



        // Initializing page view controller.
        _carbonTabSwipeNavigation =[[CarbonTabSwipeNavigation alloc] initWithItems:_pagesNames
                                                                          delegate:self];
        _carbonTabSwipeNavigation.toolbar.barTintColor = [DxColors colorWithHexRGB:NEW_FORMS_GREEN];
        [_carbonTabSwipeNavigation setNormalColor:[UIColor whiteColor]];
        [_carbonTabSwipeNavigation setIndicatorColor:[UIColor whiteColor]];
        [_carbonTabSwipeNavigation setSelectedColor:[UIColor whiteColor]];

    } else {
        [self prepareControllerForEdition];
    }

    [_carbonTabSwipeNavigation insertIntoRootViewController:self];

    self.pageViewController = _carbonTabSwipeNavigation.pageViewController;
}

- (UIViewController *)carbonTabSwipeNavigation:(CarbonTabSwipeNavigation *)carbontTabSwipeNavigation
                         viewControllerAtIndex:(NSUInteger)index {

    _currentPageIndex = index;
    // Create a new view controller and pass suitable data.
    FormPageViewController *formPageViewController = [[FormPageViewController alloc] init];
    formPageViewController.pageIndex = index;
    formPageViewController.formPage = _sortedPages[index];
    formPageViewController.managedObjectContext = self.managedObjectContext;
    formPageViewController.formRecord = self.formRecord;
    formPageViewController.observer = self;


    formPageViewController.view.frame = CGRectMake(0,
                                                   0,
                                                   self.view.frame.size.width,
                                                   self.view.frame.size.height);

    return formPageViewController;
}

#pragma mark - Button Actions (IBActions)

-(IBAction)send:(id)sender
{
    _timer = [NSTimer scheduledTimerWithTimeInterval:0.001
                                     target:self
                                   selector:@selector(isAlertViewShowing:)
                                   userInfo:nil
                                    repeats:YES];

    [self setButtonWithTag:self.btnBigSend.tag toHighlight:NO];

    // Disabling button to avoid double submissions.
    self.btnBigSend.enabled = NO;

    // Show alert.
    [self showAreYouReadyToSubmitFormMsg];

}

...无法全部粘贴

最佳答案

仅供测试:

子类 UIAlertView@interface MyAlertView : UIAlertView

然后替换 MyAlertView 中的所有 UIAlertView 实例 即 MyAlertView *someAlert = [[MyAlertView alloc] init.......];

然后覆盖

-(void)show {

[super show];

//Your breakpoint here

OR

NSLog([NSThread callStackSymbols]);
}

关于ios - 我有一个 UIAlertView 反复显示找不到源的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36635298/

相关文章:

ios - 如何访问公共(public)方法 objective-c 中的属性

ios - 有没有办法在 iOS 中获取图像文件的元数据?

ios - 使用 performSegueWithIdentifier() 向标识符添加撇号

ios - 抓取 UIWebView 页面标题作为 NSString

ios - 防止在 Xcode 中使用 iOS iPhone App 部署(禁用)WatchKit App

ios - Swift 运行错误

ios - CocoaPods UIImageView+AFNetworking.h 无法识别的选择器 setImageWithURLRequest

ios - SceneKit - 线程 - 在哪个线程上做什么?

xcode - 尚不支持类变量

ios - 我们如何在 xCode iOS 中隐藏敏感数据