Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
加载页面时,IPhone应用程序在UITableView中滚动到给定位置_Iphone_Xcode_Xcode4.2 - Fatal编程技术网

加载页面时,IPhone应用程序在UITableView中滚动到给定位置

加载页面时,IPhone应用程序在UITableView中滚动到给定位置,iphone,xcode,xcode4.2,Iphone,Xcode,Xcode4.2,我想向下滚动到表视图中的给定行。 如果我在按钮事件中使用以下代码,它将正常工作 [planTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:7 inSection:0 ] atScrollPosition:0 animated:YES]; 但是我想在页面加载之后再做。将上述代码放在viewDidLoad或ViewDidAspect中不起作用 任何帮助???UITableView都是UIScrollView的子类,因此您只

我想向下滚动到表视图中的给定行。 如果我在按钮事件中使用以下代码,它将正常工作

[planTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:7 inSection:0 ] atScrollPosition:0 animated:YES];
但是我想在页面加载之后再做。将上述代码放在viewDidLoad或ViewDidAspect中不起作用


任何帮助???

UITableView
都是
UIScrollView
的子类,因此您只需在
viewdilload:
视图中设置表视图的
contentOffset


如果需要向下滚动7个表格视图单元格的长度,请计算这7个单元格的高度(默认值为44px,但如果您有自定义单元格高度,则需要将其考虑在内),并将
contentOffset
设置为
CGPointMake(0,*计算高度*)
。对于7个44px高度的单元格,它将是
CGPointMake(0308)
UITableView
UIScrollView
的一个子类,因此您只需在
viewDidLoad:
视图中设置表视图的
contentOffset


如果需要向下滚动7个表格视图单元格的长度,请计算这7个单元格的高度(默认值为44px,但如果您有自定义单元格高度,则需要将其考虑在内),并将
contentOffset
设置为
CGPointMake(0,*计算高度*)
。对于7个44px高度的单元格,它将是
CGPointMake(0308)

这是一种黑客行为,但是您可能还需要执行-scrollToRowatinedExath:atScrollPosition:animated:并有一些延迟,因为当调用-viewDidLoad或-viewdidIspect:时,表视图行尚未创建,因此没有可滚动的内容

因此:

并在-视图中显示:

[self performSelector:@selector(doScrolling) withObject:nil afterDelay:0.3];
还要注意atScrollPosition:参数。实际上是enum:

typedef enum {
   UITableViewScrollPositionNone,
   UITableViewScrollPositionTop,
   UITableViewScrollPositionMiddle,
   UITableViewScrollPositionBottom
} UITableViewScrollPosition;

因此,如果行是可见的,并且传递了0,则不会执行任何滚动操作。这有点像黑客,但是您可能还需要执行-ScrollToRowatinePath:atScrollPosition:animated:延迟,因为当调用-ViewDiLoad或-ViewDidDisplay:时,还没有创建表视图行,因此没有可滚动的内容

因此:

并在-视图中显示:

[self performSelector:@selector(doScrolling) withObject:nil afterDelay:0.3];
还要注意atScrollPosition:参数。实际上是enum:

typedef enum {
   UITableViewScrollPositionNone,
   UITableViewScrollPositionTop,
   UITableViewScrollPositionMiddle,
   UITableViewScrollPositionBottom
} UITableViewScrollPosition;
因此,如果该行可见并且传递了0,则不会执行滚动