我注意到scrollToRowAtIndexPath:atScrollPosition:animated:
不滾動到當前不在視線中的單元格,所以如果我有100個單元格並且我需要到達70中的那個單元格,該選擇器將無能爲力。scrollToRowAtIndexPath不滾動到非活動/卸載的單元格
有沒有辦法讓這個細胞進入記憶?我已經有單元格的索引路徑...
我需要滾動到我的應用程序中的位置,當用戶想要去那裏。
感謝您的任何想法!
編輯:@dasblinkenlight
- (void)viewDidLoad
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide) name:UIKeyboardWillHideNotification object:nil];
}
- (void)keyboardWillHide
{
//Load remote cell here then scroll
// :(dont know how to load remote cell yet
}
- (void)keyboardWillShow
{
//Load remote cell here then scroll
// :(dont know how to load remote cell yet
//_cellIndexPath gets assigned on didSelectRowAtIndexPath:
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:_cellIndexPath.row inSection:_cellIndexPath.section] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
}
EDIT2:
- (void)keyboardWillShow
{
//Load remote cell here then scroll
[NSThread detachNewThreadSelector:@selector(keyboardWillShowThreaded) toTarget:self withObject:nil];
}
- (void)keyboardWillShowThreaded
{
[NSThread sleepForTimeInterval:2.0];
[self performSelectorOnMainThread:@selector(keyboardWillShowMainThread) withObject:nil waitUntilDone:YES];
}
- (void)keyboardWillShowMainThread
{
//Get the cell
//_textFieldThatHasFirstResponder is a subview in the cell
//This returns null, probably because the cell is not loaded into memory
UITableViewCell *cell = [_textFieldThatHasFirstResponder superview];
NSLog(@"CELL TO SCROLL TO: %@",cell);
NSIndexPath *indexPathForCell = [self.tableView indexPathForCell:cell];
[self.tableView scrollToRowAtIndexPath:indexPathForCell atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
}
它*應*滾動到可見區域外的單元格。你能說明你是怎麼稱呼它的嗎?你是從哪種方式來打電話的? – dasblinkenlight 2012-03-29 13:38:15
是的,也許你是對的,但我有我的8個細胞可見,當我點擊例如。第二個,它滾動得很好,但是當我點擊第8個單元格的時候,注意到會出現一些細胞,但不可見,那個看不見的單元格也不滾動。 – 2012-03-29 13:45:55
你還可以顯示你調用'scrollToRowAtIndexPath'的部分嗎? – dasblinkenlight 2012-03-29 13:48:58