2016-06-15 3 views
0

У меня есть четыре раздела в каждом разделе, есть пять строк. При прослушивании любой строки они отображают фактические данные при повторном нажатии, они показывают другой раздел данных. Я не могу понять, где я ошибаюсь. Раздел повторяя данные в другой строке. Вот мой код и изображения.Повторение ячейки ячейки в другом разделе при нажатии

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 

if (section==0) { 
    return 5; 
} 
if (section==1) { 
    return 5; 
} 
if (section==2) { 
    return 5; 
} 
if (section==3) { 
    return 5; 
} 


return 5; 
} 

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ 



    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)]; 
headerView.tag = section; 



headerView.backgroundColor = [UIColor lightTextColor]; 

UILabel *headerString= [[UILabel alloc] initWithFrame:CGRectMake(10, 0, self.view.frame.size.width-20-50,50)]; 

BOOL manyCells = [[boolenarry objectAtIndex:section] boolValue]; 

if (!manyCells) { 
    headerString.text =self.Titlearray[section] 
    }else{ 
    headerString.text =self.Titlearray[section]; 


} 

headerString.textAlignment  = NSTextAlignmentLeft; 
headerString.textColor   = [UIColor whiteColor]; 
[headerView addSubview:headerString]; 

    UITapGestureRecognizer *headerTapped = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(sectionHeaderTapped:)]; 
[headerView addGestureRecognizer:headerTapped]; 

return headerView; 
    } 
    - (UIView *)tableView:(UITableView *)tableView 
viewForFooterInSection:(NSInteger)section{ 
UIView *footer = [[UIView alloc] initWithFrame:CGRectZero]; 
return footer; 
} 

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ 
return 50; 
} 
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ 

return 2; 
    } 
    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    if ([[boolenarry objectAtIndex:indexPath.section] boolValue]) { 
    return 50; 


    } 




    return 0; 
    } 



    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 



    static NSString *CellIdentifier= @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 



     if (cell == nil) { 

     cell = [[UITableViewCell alloc] initWithStyle: 
    UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    if ([[UIDevice currentDevice] userInterfaceIdiom] == 
    UIUserInterfaceIdiomPhone) { 

    } 
} 


    BOOL manyCells = [[boolenarry objectAtIndex:indexPath.section] 
    boolValue]; 
    if (!manyCells) { 


    NSDate *object = self.Titlearray[indexPath.section]; 
    cell.textLabel.text = [object description]; 
} 
else{ 
     NSArray *content = [recipes valueForKey:[Titlearray 
objectAtIndex:indexPath.section]]; 
cell.textLabel.text = [content objectAtIndex:indexPath.row]; 
    } 


    if (indexPath.section==0) { 

    allindgre= [recipes objectForKey:@"Ingrdent"]; 
    preparetime=[recipes objectForKey:@"preparetimeing"]; 
    makingarray=[recipes objectForKey:@"makingsample"]; 


     imagearray=[[NSMutableArray alloc]initWithObjects:[UIImage 
    imageNamed:@"chickengravy1.jpg"],[UIImage 
imageNamed:@"Crispychicken.jpg"],[UIImage 
imageNamed:@"ButtermilkChk.jpg"], 

       [UIImage imageNamed:@"southernchik.jpg"], 
       [UIImage imageNamed:@"SimpleChicken.jpg"],nil]; 





     if (indexPath.row==0) { 
     cell.imageView.image= [UIImage imageNamed:@"Res Images 
    /chicken grav.jpg"]; 
    } 
    else if (indexPath.row==1) { 
     cell.imageView.image= [UIImage imageNamed:@"Res Images 
    /crispy chicken.jpg"]; 
    } 
    else if (indexPath.row==2) { 
     cell.imageView.image= [UIImage imageNamed:@"Res Images 
     /Buttermilk Chicken.jpg"]; 
    } 
    else if (indexPath.row==3) { 
     cell.imageView.image= [UIImage imageNamed:@"Res Images 
      /Southern Chicke.jpg"]; 
       } 
    else if (indexPath.row==4) { 
     cell.imageView.image= [UIImage imageNamed:@"Res Images 
     /Simple Chick.jpg"]; 


     }} 




if (indexPath.section==1) { 

    allindgre=[recipes objectForKey:@"ricerecipes"]; 
    preparetime=[recipes objectForKey:@"ricepreparetimeing"]; 
    makingarray=[recipes objectForKey:@"ricemakingsample"]; 

imagearray=[[NSMutableArray alloc]initWithObjects:[UIImage 
    imageNamed:@"Tofu Fried.jpg"],[UIImage imageNamed:@"chicken fried 
     rice.jpg"],[UIImage imageNamed:@"sweet-soy.jpg"], 
       [UIImage imageNamed:@"Southeast Asian.jpg"], 
    [UIImage imageNamed:@"Spicy Vegetable.jpg"],nil]; 




    if (indexPath.section==2) 
    { 

    allindgre=[recipes objectForKey:@"burgerrecipes"]; 
    preparetime=[recipes objectForKey:@"bugerpreparetimeing"]; 
    makingarray=[recipes objectForKey:@"bmakingrecipes"]; 




      imagearray=[[NSMutableArray alloc]initWithObjects:[UIImage 
    imageNamed:@"burger/blue burger.jpg"],[UIImage 
    imageNamed:@"burger/serrano pepper.jpg"],[UIImage 
    imageNamed:@"burger/smak bloody mary.jpg"], 
       [UIImage imageNamed:@"burger/italian style 
     meatball.jpg"], 
       [UIImage imageNamed:@"burger/Gold Nugget 
     Burger.jpg"],nil]; 

    if (indexPath.row==0) { 
     UIImage *omeltte=[UIImage imageNamed:@"Images/buger.png"]; 
     cell.imageView.image = omeltte; 


     } 
     } 




if (indexPath.section==3) 




{ 


    allindgre=[recipes objectForKey:@"pizzarecipes"]; 
    preparetime=[recipes objectForKey:@"pizzapreparetimeing"]; 
    makingarray=[recipes objectForKey:@"pmakingrecipes"]; 

    imagearray=[[NSMutableArray alloc]initWithObjects:[UIImage imageNamed:@"burger/Garlic Chicken Pizza.jpg"],[UIImage imageNamed:@"burger/Pizza On The Grillr.jpg"],[UIImage imageNamed:@"burger/BBQ Chicken Pizza.jpg"], 
       [UIImage imageNamed:@"burger/Veggie Pizza.jpg"], 
       [UIImage imageNamed:@"burger/Four Cheese Margherita Pizza.jpg"],nil]; 



    if (indexPath.row==0) { 


     UIImage *pizza=[UIImage imageNamed:@"Images/pizza.png"]; 

     cell.imageView.image = pizza; 
    } 

} 

[[cell contentView] setBackgroundColor:[UIColor clearColor]]; 
[[cell backgroundView] setBackgroundColor:[UIColor clearColor]]; 
[cell setBackgroundColor:[UIColor clearColor]]; 


[[cell textLabel]setTextColor:[UIColor blackColor]]; 

UIImage *background = [self cellBackgroundForRowAtIndexPath :indexPath]; 

UIImageView *cellBackgroundView = [[UIImageView alloc] initWithImage:background]; 
cellBackgroundView.image = background; 
cell.backgroundView = cellBackgroundView; 



return cell; 


    } 




     #pragma mark - gesture tapped 
    - (void)sectionHeaderTapped:(UITapGestureRecognizer *)gestureRecognizer{ 
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:gestureRecognizer.view.tag]; 


    if (indexPath.row==0) { 

    BOOL collapsed = [[boolenarry objectAtIndex:indexPath.section] boolValue]; 
    collapsed  = !collapsed; 
    [boolenarry replaceObjectAtIndex:indexPath.section withObject:[NSNumber numberWithBool:collapsed]]; 

} 

       //reload specific section animated 
    NSRange range = NSMakeRange(indexPath.section,1); 
    NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range]; 
    [self.tableView reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationFade]; 



    } 

      #pragma mark - Segues 





    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender: 
    (id)sender { 



    if ([[segue identifier] isEqualToString:@"showDetail"]) { 

     NSIndexPath *indexPath = [self.tableView 
     indexPathForSelectedRow]; 


    DetailViewController *destViewController= 
    segue.destinationViewController; 


     destViewController.detailItem = [[recipes objectForKey: 
     [Titlearray objectAtIndex:indexPath.section ]] 
objectAtIndex:indexPath.row]; 



    NSString*allrec= [allindgre objectAtIndex:indexPath.row]; 
    [[segue destinationViewController]setPtext:allrec]; 



    NSString*preparetim =[preparetime objectAtIndex:indexPath.row]; 

    [[segue destinationViewController] setPretime:preparetim]; 


    NSString*make=[makingarray objectAtIndex:indexPath.row]; 

    [[segue destinationViewController]setMethetext:make]; 



    UIImage*imagestring=[imagearray objectAtIndex:indexPath.row]; 

    [[segue destinationViewController] setImagess:imagestring]; 
}} 

enter image description here enter image description here

+2

вы можете показать нам какой-нибудь код? – Mahesh

+0

Я добавляю весь мой код –

+0

, какие данные повторяются? ячейку или заголовок? можете ли вы показать свой метод rowselect? – Mahesh

ответ

0

Я не знаю, что вы пытаетесь для этого ... Но попробовать, как следующие, я надеюсь, что это поможет вам:

Предположит, что вы отображение даты и название:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath (NSIndexPath *)indexPath{ 
     if (indexPath.section == 0){ 
      NSPredicate *predicate = [NSPredicate predicateWithFormat:@"Category =[cd] %@", @"Category 1"]; 
      NSArray * catArray = [self.notes filteredArrayUsingPredicate:predicate]; 
      cell.textLabel.text = [[catArray objectAtIndex:indexPath.row] objectForKey:@"Title"]; 
      cell.detailTextLabel.text = [[catArray objectAtIndex:indexPath.row] objectForKey:@"Date"]; 

     } else if (indexPath.section == 1){ 
      NSPredicate *predicate = [NSPredicate predicateWithFormat:@"Category =[cd] %@", @"Category 1"]; 
      NSArray * catArray = [self.notes filteredArrayUsingPredicate:predicate]; 
      cell.textLabel.text = [[catArray objectAtIndex:indexPath.row] objectForKey:@"Title"]; 
      cell.detailTextLabel.text = [[catArray objectAtIndex:indexPath.row] objectForKey:@"Date"]; 
     } 
    } 

нравится этот . .