iOS:重置UIPickerView EXC_BAD_ACCESS错误

时间:2015-12-10 14:03:18

标签: ios objective-c uipickerview exc-bad-access

我正在使用PickerView选择值,我想重置它,(因此它不会显示先前的选择)按下按钮后。

问题是我总是得到两个错误之一,它从一次运行变为运行而没有明显的模式。

有谁知道可能导致错误的原因,分别是如何解决问题?

代码:

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

@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;

错误:

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

1 个答案:

答案 0 :(得分:3)

首先也是最重要的 - 停止使用手动内存管理。

第二个关于崩溃,看起来两个崩溃相关并由同一个问题引起(由于你给我们的代码,不可能猜到究竟是什么让应用程序崩溃),显然你的pickerView在[pickerView reloadAllComponents]之前的某个地方发布了;被称为。

可能是因为[pickerView removeFromSuperview]引起的;在viewDidLoad中,例如,如果你选择了pickerView或类似的东西。