2012-07-25 65 views
1

我有一個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次,我怎麼能讓這個更快?

+0

我看不出有任何理由,這種外觀定製應影響這一點,除非你弄亂了圖像尺寸。你的cellForRowAtIndexPath是什麼樣的? – Weston 2012-07-25 13:18:29

+0

用一點額外的信息編輯。 – 2012-07-25 20:17:59

回答

0

我有一個應用程序,我正在努力,我有一些類似的自定義。我建議重新使用設置控件...您可以通過創建一個UITableViewCell子類並在其中設置您的seg控件來實現此目的,然後您可以爲需要自定義的事物創建插座。

快速搜索發現這個教程,它看起來像什麼我談論

UITableViewCell Prototype Tutorial

這樣你的電池將完全可重複使用的,因此,要快得多。

但是,我現在不是你的確切用例,所以也許這不適用於你。它加快了自定義按鈕,藝術和動畫相當多的細胞。

只記得alloc inits很慢。

我想另一個選擇是將之前的初始化所有可以與對照,也許它們存儲在後陣只加載它們的cellForRowAtIndexPath: