【发布时间】:2017-12-14 01:21:40
【问题描述】:
面临的问题
(线程 1:EXC_BAD_ACCESS)
。尝试了很多,但我无法解决它。以下是我尝试过的代码。在NSDictionary *thisRow = [self. EmployeeArr objectAtIndex:row]; 遇到问题
(在这里遇到问题,问题是“线程 1:EXC_BAD_ACCESS”)。请帮我找出问题所在。 TIA
EmployeesVC.h
@interface Employees : UITableViewController<CacheDBDelegate,JsonServiceClsDelegate,UITableViewDataSource,UITableViewDelegate> {
CacheDBCommands *cacheDB;
MBProgressHUD *countryHUD;
JsonServiceCls *JsonServicePostData;
OverlayViewController *ovController;
NSArray *IndexTitles;
NSMutableArray *listOfItems;
NSMutableArray *citylistOfItems;
NSMutableArray *copyListOfItems;
NSMutableArray *EmployeeArr;
BOOL searching;
BOOL letUserSelectRow;
}
@property (retain, nonatomic) NSMutableArray *EmployeeArr;
@end
EmployeesVC.m
#pragma mark -
#pragma mark Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return [self.EmployeeArr count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = [indexPath row];
static NSString *MyIdentifier = @"tableCell";
CustomMaster *cell = (CustomMaster *) [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomMaster" owner:self options:nil];
for (id currentObject in topLevelObjects){
if ([currentObject isKindOfClass:[UITableViewCell class]]){
cell = (CustomMaster *) currentObject;
}
}
}
**NSDictionary *thisRow = [self. EmployeeArr objectAtIndex:row];
(Getting issue here, the issue is "Thread 1: EXC_BAD_ACCESS")**
cell.label1.text = [thisRow objectForKey:@"Name"];
if(_WSConstEmployeeID !=nil && ![_WSConstEmployeeID isEqual:@"0"] && ![_WSConstEmployeeID isEqual:@""] &&_WSConstEmployeeSelectedIndex ==row )
{
cell .accessoryType=UITableViewCellAccessoryCheckmark;
}
else {
cell .accessoryType=UITableViewCellAccessoryNone;
}
NSString *str=[thisRow objectForKey:@"Id"];
NSString *stra=_WSConstEmployeeID;
if ([str isEqualToString:stra]) {
cell.accessoryType=UITableViewCellAccessoryCheckmark;
cell.highlighted=YES;
}else
{
cell.accessoryType=UITableViewCellAccessoryNone;
}
return cell;
}
【问题讨论】:
-
你在哪里初始化 CountryArr?
-
我似乎正在访问超出数组范围的索引项。检查是否
row < CountriesArr.count] -
在哪里声明和初始化你的 CountryArr ?
-
EmployeeArr计数可以大于CountriesArr计数。您不应通过基于EmployeeArr计数的索引来获取国家/地区对象。 -
这是 EmployeeArr 而不是 CountryArr。我已经更新了代码。请通过它
标签: ios objective-c iphone xcode uitableview