2011-09-02 33 views
1

在我的应用程序中,五个标签栏正在使用。在第五个标签中有一个表视图在那里im检索和数组并显示在表视图。数组内容在NSLog.But中正确显示只有阵列中的第一个内容显示在单元格中。任何人都可以帮助我如何解决这个问题,请.. 下面是我使用的代码,任何人都可以给我一个手,哪里会出错,请..表重新加载数据不起作用

这里是其中IM添加内容

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

这里是IM以便在检索内容(第五选项卡)

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

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

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

而不是你有什么。

+0

非常感谢后4 minutes.Please我会接受它告诉我,为什么它没有显示内容,无需重新发布应用程序 – Senorina

+0

退出并重新,或回到主屏幕并重新进入应用程序? – jrturton

+0

@ jrturton,即按主页按钮,并再次采取app.also当再次运行在模拟器它显示 – Senorina

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]; 
} 
+0

@senorina可以更清楚地告诉我你的问题 – Robin

+0

当保存数组内容时,它正在回顾另一个选项卡,当移动到该选项卡时它没有显示任何内容。但是当我按Home按钮并再次将应用程序正确显示在表格视图中。为什么它是这样? – Senorina