在UITableView中设置滚动位置

Mus*_*afa 27 cocoa-touch objective-c uitableview ios

我有一个类似于iPhone的Contact应用程序工作的应用程序.当我们添加新的联系人时,用户将被定向到包含联系信息的仅查看屏幕.如果我们从导航栏中选择"所有联系人",则用户将导航到最近添加的联系人所在的所有联系人列表.

我们可以使用以下方法将视图移动到特定行:

    [itemsTableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionBottom];
Run Code Online (Sandbox Code Playgroud)

......但它不起作用.我在打电话后正确地说这个:

    [tableView reloadData];
Run Code Online (Sandbox Code Playgroud)

我想我不打算selectRowAtIndexPath:animated:scrollPosition在这里打电话给方法.但如果不在这里,那么在哪里?

是否有任何委托方法在以下方法后调用?

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
Run Code Online (Sandbox Code Playgroud)

squ*_*art 61

我想我有一个类似的应用程序:项目列表.点击"+" - >新屏幕,返回并查看更新列表,滚动显示底部添加的项目.

总之,我把reloadDataviewWillAppear:animated:scrollToRowAtIndexPath:...viewDidAppear:animated:.

// Note: Member variables dataHasChanged and scrollToLast have been
// set to YES somewhere else, e.g. when tapping 'Save' in the new-item view.

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    if (dataHasChanged) {
        self.dataHasChanged = NO;
        [[self tableView] reloadData];
    } else {
        self.scrollToLast = NO; // No reload -> no need to scroll!
    }
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    if (scrollToLast) {
        NSIndexPath *scrollIndexPath = [NSIndexPath indexPathForRow:([dataController count] - 1) inSection:0];
        [[self tableView] scrollToRowAtIndexPath:scrollIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
    }
}
Run Code Online (Sandbox Code Playgroud)

我希望这有帮助.如果您在列表中间添加一些内容,则可以轻松滚动到该位置.


Bir*_*rju 6

你可以尝试这个,当我点击uitableview的按钮滚动时,我的应用程序在某种类似的你.

[tableviewname setContentOffset:CGPointMake(0, ([arrayofcontact count]-10)*cellheight) animated:YES];
Run Code Online (Sandbox Code Playgroud)

10表示要向上滚动的单元格数

希望对你有帮助:-)