简体   繁体   English

iOS:重置UIPickerView EXC_BAD_ACCESS错误

[英]iOS: Resetting UIPickerView EXC_BAD_ACCESS Error

I am using a PickerView to choose values and I want to reset it, (so it doesn't show the previous selection) after pressing a button. 我正在使用PickerView选择值,我想在按下按钮后将其重置(因此它不会显示先前的选择)。

The problem is I am always getting one of two errors, it changes from run to run with no apparent pattern. 问题是我总是遇到两个错误之一,它在运行过程中不断变化,没有明显的模式。

Does anyone know what might cause the errors, respectively how to solve the problem? 有谁知道可能导致错误的原因,以及如何解决问题?

Code: 码:

NSString * chosen;
NSString * elemString;
NSMutableArray *secondTableArray ;
NSInteger p = 0;
@implementation LagerViewController
@synthesize requestObject;
@synthesize choosenDocKind;
@synthesize pickerView1;

#pragma mark - View lifecycle
- (void)viewDidLoad
{
    [super viewDidLoad];
    secondTableArray = [[NSMutableArray alloc] init];
    secondTableView.scrollEnabled = YES;
    secondTableView.bounces = YES;
    elemString = @"";
    choosenDocKind = [[NSString alloc] initWithString:@""];
    [pickerView removeFromSuperview]; 
}

- (void)tableView:(UITableView *)theTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(pickerViewItems != nil)
    {
        [pickerViewItems release];
        pickerViewItems = nil;
    } 
    if((indexPath.section == 1)&&(indexPath.row == 0))
    {
        NSString * temp = [[NSString stringWithFormat:@"%@",elemString] copy];
        NSString * tableString;
        if([temp length] == 0) {
             [secondTableArray removeAllObjects];
             [secondTableView reloadData];  
             elemString = [[NSString stringWithFormat:@"ARTIKEL: %@ %@ %@", matchcode, quantity, choosenDocKind] copy];
             tableString = [[NSString stringWithFormat:@"%@ %@ %@", matchcode, quantity, choosenDocKind] copy];

             // THESE 2 ROWS BELOW CAUSE THE ERRORS
             [pickerView reloadAllComponents];
             [pickerView selectRow:0 inComponent:0 animated:YES];
        }
    }
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
    [theTableView deselectRowAtIndexPath:indexPath animated:YES];
}

#pragma mark - button events
- (IBAction)btnSubmitPVSelection:(id)sender
{
    if([choosenPrompt isEqualToString:NSLocalizedString(@"DOCUMENT_REQUEST_LAGER_UM", nil)])
    {
        if(choosenDocKind != nil)
        {
            chosen = choosenDocKind;
            [choosenDocKind release];
            choosenDocKind = nil;
        }
        choosenDocKind = [[[NSString alloc] initWithString:[pickerViewItems objectAtIndex:[pickerView selectedRowInComponent:0]]] retain];
    }
    [tvArchDocParam reloadData];
    if(choosenPrompt != nil)
    {
        [self.presentedViewController dismissViewControllerAnimated:NO completion:nil];
        [choosenPrompt release];
        choosenPrompt = nil;
    }
    [pickerView reloadAllComponents];
    [pickerView selectRow:0 inComponent:0 animated:YES];
}

.h 。H

@interface ... {
    DocRequest *requestObject;
    NSArray *pickerViewItems;
    NSString *choosenPrompt;
    UITextView *matchtext;
    IBOutlet UITableView *tvArchDocParam;
    UIAlertController *actionSheet;
    UITableView *theTableView;
    IBOutlet UITableView *secondTableView;
}   
@property (nonatomic, retain)DocRequest* requestObject;
@property (nonatomic, retain)UIPickerView *pickerView1;
-(UITableViewCell*)getSelectorCell:(NSString*)CellIdentifier;
-(UITableViewCell*)getTextFieldCell:(NSString*)CellIdentifier;
-(void)showPickerView;

Errors: 错误:

1. Thread 1: EXC_BAD_ACCESS
2. Terminating app due to uncaught exception 'NSInvalidArgumentException', reason NSDictionaryM reloadAllComponents

First and most important — stop using manual memory management. 首先也是最重要的-停止使用手动内存管理。

Second about crashes, looks like both crashes related and caused by the same issue (due to code you gave us, it's impossible to guess what exactly make app crash), obviously your pickerView was released somewhere before [pickerView reloadAllComponents]; 第二个关于崩溃的问题,看起来既与崩溃相关,又是由相同的问题引起的(由于您提供的代码,无法猜测到底是什么导致应用崩溃),显然您的pickerView是在[pickerView reloadAllComponents]之前的某个地方发布的; was called. 被称为。

It may be caused because of [pickerView removeFromSuperview]; 这可能是由于[pickerView removeFromSuperview]引起的; in viewDidLoad for example if you pickerView is assign or something like that. 例如在viewDidLoad中,如果您分配了pickerView或类似的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM