我有一个 tableviewcontroller,特别是在我的应用程序中,滚动时有点紧张。
我相当肯定这是因为我的自定义 UISegmentedControl 外观,我的表中有四个,每个都在自己的单元格中。
我在我的应用程序委托中使用此代码来自定义它们:
[[UISegmentedControl appearance] setBackgroundImage:[[UIImage imageNamed:@"SegmentedControl.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 4, 0, 4)] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setBackgroundImage:[[UIImage imageNamed:@"SegmentedControlSelected.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 4, 0, 4)] forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setDividerImage:[UIImage imageNamed:@"SegmentedControlDivider.png"] forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setDividerImage:[UIImage imageNamed:@"SegmentedControlSelectedDivider.png"] forLeftSegmentState:UIControlStateSelected rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setDividerImage:[UIImage imageNamed:@"SegmentedControlSelectedDivider.png"] forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
[UIColor grayColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, -1)], UITextAttributeTextShadowOffset,
[UIFont fontWithName:@"Georgia-Italic" size:0.0], UITextAttributeFont,
nil] forState:UIControlStateNormal];
为什么这会导致速度如此缓慢?我可以做些什么来提高性能?当它们出现在屏幕上时,它会抖动。我以前从来没有遇到过这样的问题。
我相当确定它的开关和分段控件,因为当我移除它们时,它会加速并且变得如丝般顺滑。我基本上是这样做的:
if (indexPath.row == 0)
{
cell.textLabel.text = @"text";
UISegmentedControl *segControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"1", @"2", nil]];
[segControl setSelectedSegmentIndex:[myBool boolValue]];
[segControl setSegmentedControlStyle:UISegmentedControlStyleBar];
[segControl addTarget:self action:@selector(myMethod:) forControlEvents:UIControlEventValueChanged];
cell.accessoryView = segControl;
}
在我的cellForRowAtIndexPath
7 次中,我怎样才能让它更快?