【发布时间】:2015-12-10 14:03:18
【问题描述】:
我正在使用 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
【问题讨论】:
-
如何声明pickerView,在哪里创建?
-
展示如何声明所有变量和 UIPickerViewDataSource 方法
-
再一次——展示你如何创建 pickerView1 以及你在哪里显示/隐藏它。显示例如你在做什么 - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view。您崩溃的肯定原因是内存管理,可能是因为 pickerView 或与其中显示项目相关的东西。所以你展示的更多 - 关于崩溃我可以告诉你更多
标签: ios objective-c uipickerview exc-bad-access