0

I have 2 tables view . One is with category and the other with videos .I added the favorite song into an array . But how can i reload my table with only the favorite videos when favorite category is selected ?

This is what i was trying but my table view is empty.

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

    if (tableView.tag==0) {

    TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell=[[TableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
    }

    int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];

    cell.title.text=[[stories objectAtIndex: indexPath.row] objectForKey: @"title"];
   NSString * aux=[[stories objectAtIndex: indexPath.row] objectForKey: @"url"];
    NSString *   videoHTML =[NSString stringWithFormat: @"<iframe type=\"text/html\" width=\"100\" height=\"80\" src=\"%@\" frameborder=\"0\"></iframe>",aux] ;


        NSString *imagine=[[stories objectAtIndex:indexPath.row]objectForKey:@"thumbnail"];
        cell.imageSong.image=[UIImage imageNamed:imagine];
        NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:imagine]];
        cell.imageSong.image = [UIImage imageWithData:imageData];
        cell.imageSong.contentMode=UIViewContentModeScaleAspectFit;

        return cell;
}


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

    if (!tableView.tag==0) {

        int row =indexPath.row;
        if (row==0) {
            self.title1.text=@"ALL SONGS";
            [stories removeAllObjects];
            [self parse];
            i=0;
            [self showMenu:nil];


        }

        else if (row==1) {

            self.title1.text=@"FAVORITE";
             b=[favoriteArray count];
            if (b==0) {
                NSLog(@"NSArray empty");
                [[[UIAlertView alloc]initWithTitle:@"Attention !" message:@"No videos !" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]show];


            }

            else{
                [stories removeAllObjects];
                [self.tableView reloadData];
                i=0;
                [self showMenu:nil];
            }



        }
        else
        {
        self.title1.text=[categoryArray objectAtIndex:indexPath.row-1];
        [stories removeAllObjects];
        NSString * path =[feeds objectAtIndex:indexPath.row-1];
        [self parseXMLFileAtURL:path];
        i=0;
        [self showMenu:nil];}
        self.karaokeBTn.hidden=YES;
        self.menu.hidden=NO;
        self.title1.hidden=NO;
    }



-(void)parse{
    if ([stories count] == 0) {
        for (int i=0; i<[feeds count]; i++) {
            NSString * path =[feeds objectAtIndex:i];
            [self parseXMLFileAtURL:path];

        }

    }
}

In favorite array i already have the url for video, title and image . i dont need to parse the feed again.

2
  • Yes. I have feeds. when app starts the feed is parse , and i want to have the option "favorite song" . For this i dont need to parse again , because i already have the information needed in favoriteArray.
    – Nicole SD
    Feb 19, 2015 at 11:47
  • Great, I've just posted an answer. Check if it helps you.
    – Rukshan
    Feb 19, 2015 at 11:55

2 Answers 2

1

Maybe you want to reload your table after parsing:

-(void)parse{
    if ([stories count] == 0) {
        for (int i=0; i<[feeds count]; i++) {
            NSString * path =[feeds objectAtIndex:i];
            [self parseXMLFileAtURL:path];

        }
        [self.tableView reloadData]; 
    } 
2
  • i dont need to parse again , because i already have the objects for favoriteArray. I just want to dispayed in my tableView when , i select FAVORITE cell .
    – Nicole SD
    Feb 19, 2015 at 14:38
  • so two possibles in your case: 1. replace the story array with the entries of the favoriteArray. 2. your datasource change to the favoriteArray so - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {} set a case for favourite and normal also with cellForRowAtIndexPath.
    – a_JAguar
    Feb 20, 2015 at 7:38
0

I'm not exactly sure if I understood your issue. But since you said your tableView is empty heres a possible solution.

How do you set stories array? If it's a asynchronous data fetch from web, you have a empty stories array when those delegate methods get called.

You have to reload table view once data fetching is done. On the completion block of your data fetching method.

[self.tableView reloadData];

1
  • when FAVORITE cell is selected i want to take items from favoriteArray to populate table view , not from stories array.
    – Nicole SD
    Feb 20, 2015 at 7:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.