我有一個tableviewcontroller,特別是在我的應用程序中,當滾動時會有點不安。應用藝術作品Slow Down
我相當肯定,因爲我的自定義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次,我怎麼能讓這個更快?
我看不出有任何理由,這種外觀定製應影響這一點,除非你弄亂了圖像尺寸。你的cellForRowAtIndexPath是什麼樣的? – Weston 2012-07-25 13:18:29
用一點額外的信息編輯。 – 2012-07-25 20:17:59