Senorina
Senorina

Reputation: 231

Table reload data is not working

In my app five tab bars are using.in the 5th tab one table view is there.here im retrieving and array and displaying in table view.The contents of array are displaying correctly in NSLog.But only the first content in the array is displaying in cell.Can anyone help me how to solve this issue please.. Below is the code i used and can anyone give me a hand where im going wrong please..

Here is where im adding the contents

-(IBAction)Done
{
NSString *message = [df stringFromDate:itemDate];
    NSLog(@"message1234 %@",message);
dates= [[NSMutableArray alloc] init];
            NSUserDefaults *currentDefaults7 = [NSUserDefaults standardUserDefaults];
            NSData *dataRepresentingSavedArray7 = [currentDefaults7 objectForKey:@"datingg"];
            NSMutableArray *oldSavedArray7 = [NSKeyedUnarchiver unarchiveObjectWithData:dataRepresentingSavedArray7];
    if(dates!=nil)
        {

            dates = [[NSMutableArray alloc] initWithArray:oldSavedArray7];

        }
        [dates addObject:message];
        NSUserDefaults *currentDefaults3 = [NSUserDefaults standardUserDefaults];
        [currentDefaults3 setObject:[NSKeyedArchiver archivedDataWithRootObject:dates] forKey:@"datingg"];
        [currentDefaults3 synchronize];
        NSLog(@"%@dates ate getting heree",dates);

Here is where im retreiving the contents(fifth tab)

- (void)viewWillAppear:(BOOL)animated

    {
        NSLog(@"ddddd");
        NSUserDefaults *currentDefaults = [NSUserDefaults standardUserDefaults];
        NSData *dataRepresentingSavedArray = [currentDefaults objectForKey:@"datingg"];
        NSMutableArray *oldSavedArray = [NSKeyedUnarchiver unarchiveObjectWithData:dataRepresentingSavedArray];
        datedisplay = [[NSMutableArray alloc] initWithArray:oldSavedArray];
        NSLog(@"%@",datedisplay);

        [self.tab reloadData];
        [super viewWillAppear:animated];
    }

    - (void)viewDidAppear:(BOOL)animated
    {




        [super viewDidAppear:animated];
    }

    - (void)viewWillDisappear:(BOOL)animated
    {
        [super viewWillDisappear:animated];
    }

    - (void)viewDidDisappear:(BOOL)animated
    {
        [super viewDidDisappear:animated];
    }

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        // Return YES for supported orientations
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }

    #pragma mark - Table view data source

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
    //#warning Potentially incomplete method implementation.
        // Return the number of sections.
        return 1;
    }

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
    //#warning Incomplete method implementation.
        // Return the number of rows in the section.
        return 1;
    }

    - (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] autorelease];
        }
        if(i<[datedisplay count])
        {
        // Configure the cell...
          cell.textLabel.text=[datedisplay objectAtIndex:i];
        i++;
        }
        [self.tab reloadData];                       
        return cell;
    }

    /*
    // Override to support conditional editing of the table view.
    - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
    {
        // Return NO if you do not want the specified item to be editable.
        return YES;
    }
    */

    /*
    // Override to support editing the table view.
    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
    {
        if (editingStyle == UITableViewCellEditingStyleDelete) {
            // Delete the row from the data source
            [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
        }   
        else if (editingStyle == UITableViewCellEditingStyleInsert) {
            // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
        }   
    }
    */

    /*
    // Override to support rearranging the table view.
    - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
    {
    }
    */

    /*
    // Override to support conditional rearranging of the table view.
    - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
    {
        // Return NO if you do not want the item to be re-orderable.
        return YES;
    }
    */

    #pragma mark - Table view delegate

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        // Navigation logic may go here. Create and push another view controller.
        /*
         <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
         // ...
         // Pass the selected object to the new view controller.
         [self.navigationController pushViewController:detailViewController animated:YES];
         [detailViewController release];
         */
    }

   @end
    In NSLog it is showing
    Reminder[6448:207] (
        "02 04-12",
        "02 03-12",
        "03 04-20"
    )
![enter image description here][1]  

Upvotes: 1

Views: 660

Answers (2)

Robin
Robin

Reputation: 10011

Instead of this

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return 1;
}

use

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return [datedisplay count];
}

Upvotes: 4

jrturton
jrturton

Reputation: 119262

You are telling your table it only has one row.

(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{
     return [datedisplay count];
 }

Instead of what you have.

Upvotes: 2

Related Questions