2014-12-10 4 views
0

У меня есть два UIViewControllers с табличным просмотром. Когда первая ячейка загружается во второй UIViewController, она вызывает cellForRowAtIndexPath в том же классе, но когда она загружает вторую ячейку, она вызывает первый viewControllers cellForRowAtIndexPath.UITableView, вызывающий другой UITableView cellForRowAtIndexPath

Мой код выглядит следующим образом:

SecondViewController:

- (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; 
} 

FirstViewController:

- (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; 
    } 

Спасибо заранее.

+0

Итак, каков ваш вопрос? –

+0

Почему первый элемент viewcontroller forRowAtIndexPath вызывается во втором viewController –

+1

Если вы не изменили источник данных tableview, маловероятно, что он вызывает метод других классов. Какое поведение вы видите точно? – Paulw11

ответ

0

Прежде всего, я бы сказал, извините за этот глупый вопрос. Проблема возникает из-за источника данных tableview, который определяется @ Paulw11, @Onik IV, @ Kannan Vora. secondViewControllertableView имеет источник данных firstViewController.

Смежные вопросы