UITableViewController或UIViewController中使(<UITableViewDataSource,UITableViewDelegate>)
后viewWillAppear:(BOOL)animated不执行
解决方法如下:
先在 *.h 头文件里加上<UINavigationControllerDelegate>
接着在*.m 文件里加上相关代码
self.navigationController.delegate=self;
再使用此时navigationController的代理函数,就OK了。
-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
[viewController viewWillAppear:animated];
}
-(void)viewWillAppear:(BOOL)animated
{
NSLog(@"现在可以使用了");
}
代码实例:
MyOrders.h
@interface MyOrders : UIViewController<UITableViewDataSource,UITableViewDelegate,UINavigationControllerDelegate>{
}
@property(nonatomic,retain)IBOutlet UITableView *table;
MyOrders.m
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.delegate=self;
}
-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
[viewController viewWillAppear:animated];
}
-(void)viewWillAppear:(BOOL)animated
{
NSLog(@"现在可以使用了");
}