Ios UITableView调用另一个UITableView单元格forrowatinexpath
我有两个带tableview的UIViewController。当第一个单元格加载到第二个UIViewController中时,它调用同一类中的CellForRowatineXpath,但当它加载第二个单元格时,它调用第一个ViewController CellForRowatineXpath 我的代码如下: 第二视图控制器: FirstViewController:Ios UITableView调用另一个UITableView单元格forrowatinexpath,ios,objective-c,iphone,uitableview,Ios,Objective C,Iphone,Uitableview,我有两个带tableview的UIViewController。当第一个单元格加载到第二个UIViewController中时,它调用同一类中的CellForRowatineXpath,但当它加载第二个单元格时,它调用第一个ViewController CellForRowatineXpath 我的代码如下: 第二视图控制器: FirstViewController: 提前谢谢。首先,我要为这个愚蠢的问题道歉。 问题是由@Paulw11、@Onik IV、@Kannan Vora指定的table
提前谢谢。首先,我要为这个愚蠢的问题道歉。
问题是由@Paulw11、@Onik IV、@Kannan Vora指定的tableview数据源造成的。secondViewController tableView的数据源为firstViewController。那么,您的问题是什么?除非您更改了tableView的数据源,否则它不太可能调用其他类方法。你到底看到了什么行为?你是否设置了一个断点来确认你声称的行为?tableView在数以百万计的应用程序中使用,因此不太可能存在您所描述的bug。问题一定出在dataSource委托中,如果您是通过代码创建这两个tableView,请将代码放在这里以帮助您。如果要在脚本中创建,请确保每个tableView的数据源都是其viewController。请确保已设置正确tableView的dataSource属性
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NotificationsTableViewCell *cell = [self.notificationsTableView dequeueReusableCellWithIdentifier:@"NotificationCell"];
if(cell == nil)
{
cell = [[NotificationsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"NotificationCell"];
}
NSMutableDictionary *cellData = [self.databaseCall transactionFromDatabase:indexPath.row];
NSLog(@"%@", cellData);
cell.goalNameLabel.text = [cellData objectForKey:@"categoryName"];
NSString *cardTypeId = [cellData objectForKey:@"cardTypeId"];
NSString *tipsId = [cellData objectForKey:@"tipsId"];
if([self.defaultCardTypeId containsObject:cardTypeId])
{
NSUInteger index = [self.defaultCardTypeId indexOfObject:cardTypeId];
[self.defaultCardTypeId replaceObjectAtIndex:index withObject:cardTypeId];
}
else{
[self.defaultCardTypeId addObject:cardTypeId];
}
if([self.defaultTipId containsObject:tipsId])
{
NSUInteger index = [self.defaultCardTypeId indexOfObject:cardTypeId];
[self.defaultTipId replaceObjectAtIndex:index withObject:cardTypeId];
}
else{
[self.defaultTipId addObject:tipsId];
}
if([cardTypeId isEqualToString:@"1"])
{
UIImage *cellImage = [UIImage imageNamed:@"icon2.jpg"];
cell.cardTypeImage.image = cellImage;
cell.cardTypeLabel.text = @"GOOD TO KNOW";
cell.cardTypeLabel.textColor = [UIColor colorWithRed:252/255.0 green:171/255.0 blue:19/255.0 alpha:1];
}
if([cardTypeId isEqualToString:@"2"])
{
UIImage *cellImage = [UIImage imageNamed:@"icon1.jpg"];
cell.cardTypeImage.image = cellImage;
cell.cardTypeLabel.text = @"TO CONSIDER";
cell.cardTypeLabel.textColor = [UIColor colorWithRed:0/255.0 green:191/255.0 blue:243/255.0 alpha:1];
}
cell.notificationCard.layer.cornerRadius = 5;
// Configure the cell...
return cell;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
GoalsCustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GoalsListCell" forIndexPath:indexPath];
if(cell == nil)
{
cell = [[GoalsCustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"GoalsListCell"];
}
NSInteger indexOfCategory = [self.databaseCall.arrColumnName indexOfObject:@"CategoryName"];
NSInteger indexOfImage = [self.databaseCall.arrColumnName indexOfObject:@"CategoryImage"];
NSInteger indexOfActive = [self.databaseCall.arrColumnName indexOfObject:@"coulmn"];
//Assigning the contents of cell
cell.goalName.text = [NSString stringWithFormat:@"%@", [[self.arrCategoryTitle objectAtIndex:indexPath.row] objectAtIndex:indexOfCategory]];
NSString *categoryImage = [NSString stringWithFormat:@"%@", [[self.arrCategoryTitle objectAtIndex:indexPath.row] objectAtIndex:indexOfImage]];
NSString *activeStatus = [NSString stringWithFormat:@"%@", [[self.arrCategoryTitle objectAtIndex:indexPath.row] objectAtIndex:indexOfActive]];
UIImage *cellImage = [UIImage imageNamed:categoryImage];
cell.goalImage.image = cellImage;
[cell.favouriteButton addTarget:self action:@selector(favouriteButtonPressed:) forControlEvents:UIControlEventTouchDown];
NSMutableString *selectedRowImage = [[NSMutableString alloc] initWithString:@""];
//Checking whether the category is selected by user or not
if([activeStatus isEqualToString:@"yes"])
{
selectedRowImage = [NSMutableString stringWithFormat:@"starsel.png"];
}
else
{
selectedRowImage = [NSMutableString stringWithFormat:@"stardef.png"];
}
UIImage *favouriteIconImage = [UIImage imageNamed:selectedRowImage];
[cell.favouriteButton setBackgroundImage:favouriteIconImage forState:UIControlStateNormal];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
// Configure the cell...
return cell;
}