Objective c 相对于表1填充表2时,索引1超出边界

Objective c 相对于表1填充表2时,索引1超出边界,objective-c,xcode,uitableview,Objective C,Xcode,Uitableview,我希望为ios创建一个基本程序,在一个视图中使用数据数组和2个UITableView。我希望第二个UITableView由基于第一个表中所做选择的数组填充。第二个表有一个数组。当我单击表1的第一个单元格时,所需的数据显示在表2中。但当我点击表1的第二个单元格时,我得到了一个错误。“索引1超出范围” .m文件 -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; NSString *jsonString = [

我希望为ios创建一个基本程序,在一个视图中使用数据数组和2个UITableView。我希望第二个UITableView由基于第一个表中所做选择的数组填充。第二个表有一个数组。当我单击表1的第一个单元格时,所需的数据显示在表2中。但当我点击表1的第二个单元格时,我得到了一个错误。“索引1超出范围”

.m文件

-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
NSString *jsonString = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http:/url.com/technology"] encoding:NSStringEncodingConversionAllowLossy error:nil];
NSString *jsonString1 = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://url.com/experience1"] encoding:NSStringEncodingConversionAllowLossy error:nil];
NSString *jsonString2 = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http:url.com/experirnce2"] encoding:NSStringEncodingConversionAllowLossy error:nil];

SBJSON *parser = [[SBJSON alloc]init];
SBJSON *parser1 = [[SBJSON alloc]init];
SBJSON *parser2 = [[SBJSON alloc]init];

NSDictionary *results = [parser objectWithString:jsonString error:nil];
[parser release], parser = nil;
    NSDictionary *results1 = [parser1 objectWithString:jsonString1 error:nil];
    NSDictionary *results2 = [parser2 objectWithString:jsonString2 error:nil];
    [parser release], parser = nil;
    [parser1 release], parser1 = nil;
    [parser2 release], parser2 = nil;

self.technologyArray = [results objectForKey:@"response"];
self.technologyData = [technologyArray valueForKey:@"technologyname"];
self.experienceArray1 = [results1 objectForKey:@"response"];
self.experienceData1 = [experienceArray1 valueForKey:@"experiencename"];
self.experienceArray2 = [results2 objectForKey:@"response"];
self.experienceData2 = [experienceArray2 valueForKey:@"experiencename"];
experience = [[NSMutableArray alloc]initWithObjects:experienceData1, experienceData2, nil];


}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView == technologyTable)
return [technologyData count];

else {
return [experience count];
}

}



-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";


UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
// Change UITableViewCellStyle
cell = [[[UITableViewCell alloc] 
         initWithStyle:UITableViewCellStyleSubtitle 
         reuseIdentifier:CellIdentifier] autorelease];
}

    if (tableView == technologyTable)
{

   cell.textLabel.text=[technologyData objectAtIndex:indexPath.row];

} 

if (tableView == experienceTable)
{
cell.textLabel.text = [[experience objectAtIndex:indexPath.row]objectAtIndex:indexPath.row];
[experienceTable reloadData];

}
return cell ;

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView == technologyTable)
{

experienceTable = [[experience objectAtIndex:indexPath.row] objectAtIndex:indexPath.row];


selectTechnology.text = [technologyData objectAtIndex:indexPath.row];

self.technologyList.hidden = YES;

}
if(tableView == experienceTable)
{
self.experienceList.hidden = YES;
selectExperience.text = [[experience objectAtIndex:1] objectAtIndex:indexPath.row];
}
[experience release ];

}
.h文件

    {
NSMutableArray *technologyArray;
NSMutableArray *technologyData;
NSMutableArray *experienceArray1;
NSMutableArray *experienceArray2;
NSMutableArray *experienceData1;
NSMutableArray *experienceData2;

NSMutableArray *experience;
}
@property (nonatomic, retain) NSMutableArray *technologyArray;
@property (nonatomic, retain) NSMutableArray *technologyData;
@property (nonatomic, retain) NSMutableArray *experienceArray1;
@property (nonatomic, retain) NSMutableArray *experienceArray2;
@property (nonatomic, retain) NSMutableArray *experienceData1;
@property (nonatomic, retain) NSMutableArray *experienceData2;
@property (nonatomic, retain) NSMutableArray *experience;

cellforrowatinedexpath
中,当
(tableView==experienceTable)
为什么要重新加载
experienceTable
?在
didselectRowatinedexpath
中,您正在释放
experience
数组-确保这不会导致此问题。这里的经验是一个包含两个数组的数组。因此,当在表1中进行任何选择时。表2相应地填充。所以必须重新加载表,以便根据所做的选择更新数据。没有释放经验不是原因。