表重新加载数据不起作用

时间:2011-09-02 11:10:23

标签: iphone objective-c

在我的应用程序中有五个标签栏正在使用。在第五个标签页中有一个表格视图。我可以检索和排列并在表格视图中显示。数组的内容在NSLog中正确显示。但只有第一个内容在数组正在显示在单元格中。任何人都可以帮我解决这个问题。 下面是我使用的代码,任何人都可以帮我一把手,我会出错...

这是我添加内容的地方

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

这是我正在检索内容的地方(第五个标签)

- (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]  

2 个答案:

答案 0 :(得分:4)

而不是这个

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

使用

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

答案 1 :(得分:2)

你告诉你的表它只有一行。

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

而不是你拥有的。