ViewController添加UITableView使用scrollViewDidScroll popViewControllerAnimated崩溃

时间:2013-11-11 05:00:34

标签: ios iphone uitableview

这是我的所有代码:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(pushTableViewController:)];
    self.navigationItem.leftBarButtonItem = leftItem;

}
- (void)pushTableViewController:(id)sender {
    TableViewController *tableViewController = [[TableViewController alloc]init];
    [self.navigationController pushViewController:tableViewController animated:YES];

}

TableViewController代码为:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UIBarButtonItem *myMessageButton = [[UIBarButtonItem alloc] initWithTitle:@"back" style:UIBarButtonItemStylePlain target:self action:@selector(myMessageButtonClicked:)];
    self.navigationItem.leftBarButtonItem = myMessageButton;
    UITableView *scrollTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
    scrollTableView.delegate = self;
    scrollTableView.dataSource = self;
    [self.view addSubview:scrollTableView];
}
- (void)myMessageButtonClicked:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{

}

使用最简单的方法来使用UITableView,并实施scrollViewDidScroll 当我将UITableView滚动到底部,然后popViewControllerAnimated我崩溃了。 是IOS的这个BUG?或者我哪里出错?

2 个答案:

答案 0 :(得分:1)

问题是,tableview尝试在动画viewController期间访问scrollViewDidScroll委托方法。所以在达到底部滚动后,在popViewController之前将datasourcedelegate设置为Nil。

答案 1 :(得分:0)

试试这个

ExampleviewController * example = [[ExampleviewController alloc]] init];

[self.navigationController pushViewController:example animated:YES];

检查声明UIScrollView Delegate不是