27

私は、iPhone の連絡先アプリケーションの動作に似た動作をするアプリケーションを持っています。新しい連絡先ユーザーを追加すると、連絡先情報を含む表示専用画面が表示されます。ナビゲーション バーから [すべての連絡先] を選択すると、ユーザーは、最近追加された連絡先が表示されているすべての連絡先のリストに移動します。

以下を使用して、ビューを特定の行に移動できます。

    [itemsTableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionBottom];

...しかし、それは機能していません。私は呼び出した直後にこれを呼び出しています:

    [tableView reloadData];

selectRowAtIndexPath:animated:scrollPositionここでメソッドを呼び出すことは想定されていないと思います。でも、ここじゃないならどこ?

次のメソッドの後に呼び出されるデリゲート メソッドはありますか?

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
4

4 に答える 4

61

私は似たようなアプリを持っていると思います: アイテムのリスト., '+' をタップ -> 新しい画面, 戻ってきて更新されたリストを見て, スクロールして追加されたアイテムを一番下に表示します.

要約すると、私はとを入れreloadDataました。viewWillAppear: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];
    }
}

これが役立つことを願っています。リストの途中に何かを追加すると、代わりにその位置まで簡単にスクロールできます。

于 2009-01-20T04:07:59.790 に答える
6

あなたはこれを試すことができます、私がuitableviewのボタンスクロールをクリックしたときにあなたに似たある種の私のアプリケーションがアップしています。

[tableviewname setContentOffset:CGPointMake(0, ([arrayofcontact count]-10)*cellheight) animated:YES];

10は、上にスクロールするセルの数です。

これがお役に立てば幸いです:-)

于 2012-04-04T07:56:39.523 に答える
0

スクロールをテストするのに十分な数のダミーの連絡先が追加されていますか? tableView が特定のサイズの場合にのみ、iPhone がスクロールする入力を見つけるようです。

これは、私のプロジェクトで機能するコードです。前のボタンを使用しているため、通常は UITABLEVIEWSCROLLPOSITION で移動するようにテーブルビューを少し下にスクロールします。(前のセルを「見る」ことができない場合、前のボタンは機能しません。

カスタム メソッド呼び出しの一部を無視します。

- (void)textFieldDidBeginEditing:(UITextField *)textField {

    //Show the navButtons
    [self navButtonAnimation];


    DetailsStandardCell *cell = (DetailsStandardCell *)textField.superview.superview.superview;

    self.parentController.lastCell = cell;


    //Code to scroll the tableview to the previous indexpath so the previous button will work. NOTE previous button only works if its target table cell is visible.
    NSUInteger row = cell.cellPath.row;
    NSUInteger section = cell.cellPath.section;

    NSIndexPath *previousIndexPath = nil;


    if (cell.cellPath.row == 0 && cell.cellPath.section != 0) //take selection back to last row of previous section
    {
    NSUInteger previousIndex[] = {section -1, ([[self.sections objectForKey:[NSNumber numberWithInt:section - 1]]count] -1)};
    previousIndexPath = [[NSIndexPath alloc] initWithIndexes:previousIndex length:2];   
    }
    else if (cell.cellPath.row != 0 && cell.cellPath.section != 0)
    {
        NSUInteger previousIndex[] = {section, row - 1};
        previousIndexPath = [[NSIndexPath alloc] initWithIndexes:previousIndex length:2];       

    }


    [self.theTableView scrollToRowAtIndexPath: cell.cellPath.section == 0 ? cell.cellPath : previousIndexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];

}
于 2009-01-05T15:22:16.367 に答える