Iphone UITableView何时完成更新?

Iphone UITableView何时完成更新?,iphone,sdk,Iphone,Sdk,我的问题似乎很简单,但我在这里或其他地方都找不到解决办法。 在我的一个UIView中,我有一个UITableView作为子类。当应用程序完成时,最后选定的表格单元格将保存到NSUserDefaults,当应用程序重新启动时,我希望将选定的单元格设置为以前的状态。但是,当我过早地执行此操作时,会出现问题,因为节数未知,即表尚未加载其数据。所以我决定在函数numberofrowsin部分中设置它,它可以工作,但我确信这不是正确的位置 - (NSInteger)tableView:(UITableVi

我的问题似乎很简单,但我在这里或其他地方都找不到解决办法。 在我的一个UIView中,我有一个
UITableView
作为子类。当应用程序完成时,最后选定的表格单元格将保存到
NSUserDefaults
,当应用程序重新启动时,我希望将选定的单元格设置为以前的状态。但是,当我过早地执行此操作时,会出现问题,因为节数未知,即表尚未加载其数据。所以我决定在函数
numberofrowsin部分
中设置它,它可以工作,但我确信这不是正确的位置

- (NSInteger)tableView:(UITableView *)tableView 
    numberOfRowsInSection:(NSInteger)section 
{
    int iNofRows = 0; //Default  

    // It is not great doing this here but....
    if(bSetDefaultSelection == YES)  
    {  
        bSetDefaultSelection = NO; // Stop recursion  
        **NSIndexPath* indexPath =  [NSIndexPath indexPathForRow:(NSUInteger)l last_sel_row inSection:(NSUInteger)0];  
        [self selectRowAtIndexPath:indexPath animated:NO                                      scrollPosition:UITableViewScrollPositionMiddle];**  
    }  
    return iNofRows;  
}

我想你要找的地方是

- (void)viewDidAppear:(BOOL)animated;    
 // Called when the view has been fully transitioned onto the screen. Default does nothing
(有关详细信息,请参阅UIViewController) 我刚刚调试了我的应用程序,该方法在您提到的方法之后调用:

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
在您的情况下,您必须编写如下内容:

- (void)viewDidAppear:(BOOL)animated{
    NSIndexPath* indexPath = [NSIndexPath indexPathForRow:(NSUInteger)l last_sel_row inSection:(NSUInteger)0];
    [self selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionMiddle];
}

干杯

我想你要找的地方是

- (void)viewDidAppear:(BOOL)animated;    
 // Called when the view has been fully transitioned onto the screen. Default does nothing
(有关详细信息,请参阅UIViewController) 我刚刚调试了我的应用程序,该方法在您提到的方法之后调用:

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
在您的情况下,您必须编写如下内容:

- (void)viewDidAppear:(BOOL)animated{
    NSIndexPath* indexPath = [NSIndexPath indexPathForRow:(NSUInteger)l last_sel_row inSection:(NSUInteger)0];
    [self selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionMiddle];
}

干杯

嘿,谢谢你的回复。我想没有人回答得这么多,我很感激你的努力。使用“(void)viewdideappease:(BOOL)animate”的解决方案仅适用于UITableViewController,但我正在处理UITableView。 但是我决定在我的主控制器中发布一个通知,触发表进行选择,并且效果很好。
再次感谢。

嘿,谢谢你的回复。我想没有人回答得这么多,我很感激你的努力。使用“(void)viewdideappease:(BOOL)animate”的解决方案仅适用于UITableViewController,但我正在处理UITableView。 但是我决定在我的主控制器中发布一个通知,触发表进行选择,并且效果很好。 再次感谢