0

I have two UITableViews in my view which shows same contents(verses of bible) but in diffrent language,top tableview shows english and bottom-table shows hindi.everything works fine,but some chapters the verse loads the data in uitableview the application crashes,the error is in this area

- (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;

}

and also after playing too much time in uitableview ,it cause the slow down of scrolling of UITableViewCells.And there is no smooth scrolling occours.Is there any eroor in above code which i get error while loading some chapters. Thanks in advance. EDIT:

- (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];

    }



}

3 Answers 3

1

first do one thing. before use of your both array, NSLog the both array before reloading table. And check both array have same number of objects. it may be a reason of crashing.

0

in the above code first add the conditions for returning the text size for english and hindi verse. because currently you are always returning the text size of first english verse.The main problem you are facing is not in your above code.The problem should be on your another table view delegate call:- CellForRowAtIndexPath.

Can you paste your CellForRowAtIndexPath delegate call here so that i can give you more idea.

7
  • first check inside the first condition:-if(tableView == table) that your array(allSelectedVerseEnglish) has same number of object as the number of rows you are creating in tableview.Crash might be happen if your array has less number of object than the number of rows in tableView.Do the same check as above in second part of your condition:- else if(tableView == tab). Jan 10, 2012 at 4:12
  • Secondly in - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath you are always returning your first value. second part of your code will never called so it might be a reason for crash.add the condition in above delegate for example if(tableView == Hindi) return hidi text size if(tableView == English) return english textSize. Let me know if above works for you. Jan 10, 2012 at 4:20
  • not content size. The number of rows you want to create in table view should be defined in tableView delegate like:- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {. return [array1 count]; } Have you implement above delegate? Jan 10, 2012 at 4:22
  • if(tableView == table) { 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; } if(tableView == tab) { CGSize textSizehindi = [[tempArray objectAtIndex:indexPath.row] sizeWithFont:[UIFont fontWithName:@"testfont" size:18.0 ] constrainedToSize:CGSizeMake(280.0f,MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap]; return textSizehindi.height +20; } ….is this correct? Jan 10, 2012 at 4:24
  • when you are facing crash? at the time of scrolling of tableView? Jan 10, 2012 at 4:27
0

2nd part of your heightForRowAtIndexPath method is never called. It allways returning return textSize.height +20; Most possible way to crash is null pointer delegate.allSelectedVerseEnglish or unexisting font.

2
  • sir,could u please explain this how to solve this error?Thanks. Jan 10, 2012 at 3:57
  • in your code, you probably mean, that you have different sizes in different tables. in cellForRowAtIndexPath you seting different texts for them via if(tableView == ***) {...} block. you chould do the same in heightForRowAtIndexPath. Next, about your error, try post some variables in NSLog before using them. will program crash on NSLog?
    – SentineL
    Jan 10, 2012 at 4:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.