如何从类别表重新加载RootViewController中列出的tableView?

时间:2012-04-26 12:57:44

标签: iphone objective-c ios uitableview listview

我正在做一个笑话应用。主页是类别表中RootViewController中列出的类别列表。

用户执行更改时会更新数据库。问题是当我回到主页时,表格没有刷新。 当我再次运行应用程序时,可以看到更改。

我尝试了[tableView reloadData][self.tableView reloadData]但没有结果。

这里是代码:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{       
    return 1;
}   

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{
      WhySoSeriousAppDelegate *appDelegate = (WhySoSeriousAppDelegate *)[[UIApplication               sharedApplication] delegate];

      return appDelegate.jokes.count;
}    

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath    
{       
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) 
    {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier ] autorelease];

        UIView *activeColor = [[[UIView alloc] init] autorelease];
        activeColor.backgroundColor = [UIColor colorWithRed:170/256.0 green:50/256.0 blue:0/256.0 alpha:1.0];
        cell.selectedBackgroundView = activeColor;          
    }       

    WhySoSeriousAppDelegate *appDelegate = (WhySoSeriousAppDelegate *)[[UIApplication sharedApplication] delegate];
    Joke *joke = (Joke *)[appDelegate.jokes objectAtIndex:indexPath.row];   

    [cell setText:joke.category];       
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;       

    return cell;        
}

我该如何解决这个问题?

2 个答案:

答案 0 :(得分:0)

尝试使用以下代码进行更新您的UITableview:

    [table_view beginUpdates];
    [table_view deleteSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationLeft];
    [table_view insertSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationRight];
    [table_view endUpdates];

谢谢...!

答案 1 :(得分:0)

在同一个控制器的app delegate中重新加载Joke数据,以查看更改的记录。然后重新加载表视图。