OGeek|极客世界-中国程序员成长平台

标题: iOS:重置 UIPickerView EXC_BAD_ACCESS 错误 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 09:57
标题: iOS:重置 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)tableViewUITableView *)theTableView didSelectRowAtIndexPathNSIndexPath *)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)btnSubmitPVSelectionid)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*)getSelectorCellNSString*)CellIdentifier;
-(UITableViewCell*)getTextFieldCellNSString*)CellIdentifier;
-(void)showPickerView;

错误:

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



Best Answer-推荐答案


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

关于崩溃的第二个问题,看起来两者都与崩溃相关并且由同一问题引起(由于您给我们的代码,无法猜测究竟是什么导致应用崩溃),显然您的 pickerView 是在 [pickerView reloadAllComponents] 之前的某个地方发布的;被称为。

可能是因为[pickerView removeFromSuperview];例如,在 viewDidLoad 中,如果您指定了 pickerView 或类似的东西。

关于iOS:重置 UIPickerView EXC_BAD_ACCESS 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34203882/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4