2012-01-10 43 views
0

我有兩個UITableViews在我的視圖中顯示相同的內容(聖經經文),但在不同的語言,頂部tableview顯示英語和底部表顯示hindi.everything工作正常,但一些章節詩加載在UITableView的應用程序崩潰的數據,誤差在這方面UITableView內容高度問題導致應用程序崩潰

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    CGSize textSize = [[delegate.allSelectedVerseEnglish objectAtIndex:indexPath.row] sizeWithFont:[UIFont fontWithName:@"Georgia" size:18.0 ] constrainedToSize:CGSizeMake(280.0f,MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap]; 

    return textSize.height +20; 

    CGSize textSizehindi = [[tempArray objectAtIndex:indexPath.row] sizeWithFont:[UIFont fontWithName:@"testfont" size:18.0 ] constrainedToSize:CGSizeMake(280.0f,MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap]; 

    return textSizehindi.height +20; 

} 

,也打了太多的時間在後的UITableView,它會導致慢UITableViewCells.And的滾動下來,沒有平滑滾動occours 。在上面的代碼中,有一些代碼在加載某些章節時出現錯誤。 在此先感謝。 編輯:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    readCell *cell = (readCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"readCell" owner:self options:nil]; 
     cell = [nib objectAtIndex:0]; 

     cell.textLabel.lineBreakMode = UILineBreakModeWordWrap; 
     cell.textLabel.numberOfLines = 0; 

    } 
    if(tableView == table) 
    { 
     UIView *myBackView = [[UIView alloc] initWithFrame:cell.frame]; 
     myBackView.backgroundColor = [UIColor colorWithRed:250.0 green:248.0 blue:192.0 alpha:1.0]; 
     [myBackView setBackgroundColor:[UIColor colorWithRed:1 green:1 blue:0.75 alpha:1]]; 
     cell.selectedBackgroundView = myBackView; 
     [myBackView release]; 


     table.backgroundColor = [UIColor clearColor]; 
     table.separatorColor = [UIColor clearColor]; 

     cell.chapterAndVerse.text = [NSString stringWithFormat:@"%d",indexPath.row+1]; 
     cell.chapterAndVerse.font = [UIFont fontWithName:@"Georgia" size:17.0]; 
     cell.chapterAndVerse.frame=CGRectMake(0, 10, 30.0, 20.0); 
     cell.textLabel.text = [NSString stringWithFormat:@" %@",[delegate.allSelectedVerseEnglish objectAtIndex:indexPath.row]]; 

     cell.textLabel.font = [UIFont fontWithName:@"Georgia" size:18]; 

     cell.backgroundColor = [UIColor clearColor]; 

    } 




    else if(tableView == tab) 
    { 
     UIView *myBackView = [[UIView alloc] initWithFrame:cell.frame]; 
     myBackView.backgroundColor = [UIColor colorWithRed:250.0 green:248.0 blue:192.0 alpha:1.0]; 
     [myBackView setBackgroundColor:[UIColor colorWithRed:1 green:1 blue:0.75 alpha:1]]; 
     cell.selectedBackgroundView = myBackView; 
     [myBackView release]; 

     tab.backgroundColor = [UIColor clearColor]; 
     tab.separatorColor = [UIColor clearColor]; 

     cell.chapterAndVerse.text = [NSString stringWithFormat:@"%d",indexPath.row+1]; 
     cell.chapterAndVerse.font = [UIFont fontWithName:@"Georgia" size:17.0]; 
     cell.chapterAndVerse.frame=CGRectMake(0, 10, 30.0, 20.0); 
     cell.textLabel.text = [NSString stringWithFormat:@" %@",[tempArray objectAtIndex:indexPath.row]]; 

     cell.textLabel.font = [UIFont fontWithName:@"testfont" size:18]; 

     cell.backgroundColor = [UIColor clearColor]; 

    } 
     return cell; 

} 

EDIT2

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    if (tableView == table) { 
     return [delegate.allSelectedVerseEnglish count]; 
    } 
    else if (tableView == tab) 
    { 
     return [tempArray count]; 

    } 



} 

回答

0

在上面的代碼首先添加條件爲英語和印地文節返回文本大小。因爲目前你總是返回第一個英文的文本大小。你面臨的主要問題不在你的上面的代碼中。問題應該出現在你的另一個表視圖上的委託調用:--CellForRowAtIndexPath。

你可以在這裏粘貼你的CellForRowAtIndexPath委託調用,這樣我可以給你更多的想法。

+0

好的我會粘貼code.thanks。 – stackiphone 2012-01-10 03:50:33

+0

首先檢查第一個條件:-if(tableView == table)你的數組(allSelectedVerseEnglish)與你在tableview.Crash中創建的行數相同的對象數量可能會發生,如果你的數組有少量的對象比tableView中的行數要多。在您的條件的第二部分中執行與上面相同的檢查: - else if(tableView == tab)。 – 2012-01-10 04:12:06

+0

其次在 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath你總是返回你的第一個值。代碼的第二部分將永遠不會調用,所以它可能是crash.add上述委託中的條件的原因,例如if(tableView == Hindi)返回hidi文本大小if(tableView == English)return english textSize。讓我知道如果上面的作品適合你。 – 2012-01-10 04:20:14

0

您的heightForRowAtIndexPath方法的第二部分永遠不會被調用。它總是返回return textSize.height +20;最可能的崩潰方式是空指針delegate.allSelectedVerseEnglish或未知字體。

+0

先生,請你解釋一下如何解決這個錯誤?謝謝。您的代碼中的 – stackiphone 2012-01-10 03:57:00

+0

可能是指您在不同表格中具有不同的大小。在'cellForRowAtIndexPath'中,通過'if(tableView == ***){...}'塊爲他們分配不同的文本。你應該在'heightForRowAtIndexPath'中做同樣的事情。接下來,關於你的錯誤,在**使用它們之前,嘗試在'NSLog' **中發佈一些變量。將程序崩潰在'NSLog'上? – SentineL 2012-01-10 04:03:24

1

先做一件事。在使用你的兩個數組之前,在重新加載表之前,先NSLog這兩個數組。並檢查兩個數組是否具有相同數量的對象。這可能是崩潰的原因。