我有 3 个表视图和三个数据源。我用来自 XML 的数据填充它们。当我只填充一个表格视图时,所有表格视图都填充相同的文本。
所有 tableviewcells 具有相同的标识符:“AlbumCell”
这是我的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
otoFosilArray = [[NSMutableArray alloc] init];
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
updateArray = appDelegate.derinlikListesiArrayMikro;
_arrayFosiller1 = [[NSMutableArray alloc] init];
_arrayFosiller2 = [[NSMutableArray alloc] init];
_arrayFosiller3 = [[NSMutableArray alloc] init];
tableFosiller1.dataSource = self;
tableFosiller1.delegate = self;
tableFosiller2.dataSource = self;
tableFosiller2.delegate = self;
tableFosiller3.dataSource = self;
tableFosiller3.delegate = self;
[self otoFosilEkle];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
if (tableView == self.tableFosiller1) {
return 1;
}
else if (tableView == self.tableFosiller2) {
return 1;
}
else if (tableView == self.tableFosiller3) {
return 1;
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (cbvMBentik.checked == YES) {
return [_arrayFosiller1 count];
}
if (cbvMPlanktonik.checked == YES) {
return [_arrayFosiller2 count];
}
if (cbvMDiger.checked == YES) {
return [_arrayFosiller3 count];
}
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:@"AlbumCell"];
if (cbvMBentik.checked == YES)
cell.textLabel.text = [_arrayFosiller1 objectAtIndex:indexPath.row];
if (cbvMPlanktonik.checked == YES)
cell.textLabel.text = [_arrayFosiller2 objectAtIndex:indexPath.row];
if (cbvMDiger.checked == YES)
cell.textLabel.text = [_arrayFosiller3 objectAtIndex:indexPath.row];
return cell;
}
- (void)otoFosilEkle
{
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
otoFosilArray = appDelegate.derinlikListesiArrayMikroFosil;
NSString *tempStr;
for (int i = 0; i < [otoFosilArray count]; i++)
{
if ([[[otoFosilArray objectAtIndex:i] Durum] isEqualToString:@"Bentik"]) {
cbvMBentik.checked = YES;
cbvMPlanktonik.checked = NO;
cbvMDiger.checked = NO;
tableFosiller1.userInteractionEnabled = YES;
tableFosiller2.userInteractionEnabled = NO;
tableFosiller3.userInteractionEnabled = NO;
tempStr = @"text1";
[_arrayFosiller1 addObject:tempStr];
[tableFosiller1 reloadData];
}
if ([[[otoFosilArray objectAtIndex:i] Durum] isEqualToString:@"Planktonik"]) {
cbvMBentik.checked = NO;
cbvMPlanktonik.checked = YES;
cbvMDiger.checked = NO;
tableFosiller1.userInteractionEnabled = NO;
tableFosiller2.userInteractionEnabled = YES;
tableFosiller3.userInteractionEnabled = NO;
tempStr = @"text2";
[_arrayFosiller2 addObject:tempStr];
[tableFosiller2 reloadData];
}
if ([[[otoFosilArray objectAtIndex:i] Durum] isEqualToString:@"Diğer"]) {
cbvMBentik.checked = NO;
cbvMPlanktonik.checked = NO;
cbvMDiger.checked = YES;
tableFosiller1.userInteractionEnabled = NO;
tableFosiller2.userInteractionEnabled = NO;
tableFosiller3.userInteractionEnabled = YES;
tempStr = @"text3"
[_arrayFosiller3 addObject:tempStr];
[tableFosiller3 reloadData];
}
}
}