У меня есть два UITableViews, которые показывают то же содержимое (стихи библии), но на разных языках, top 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 . Есть ли какой-либо сквозной код выше, который я получаю при загрузке некоторых разделов. Спасибо заранее. 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];
}
}
ОК, я вставлю код. – stackiphone
сначала проверьте внутри первого условия: -if (tableView == table), что ваш массив (allSelectedVerseEnglish) имеет такое же количество объектов, сколько числа строк, которые вы создаете в tableview.Crash может произойти, если ваш массив имеет меньшее количество объектов чем количество строк в таблицеView.Do та же проверка, что и выше во второй части вашего условия: - else if (tableView == tab). –
Во-вторых в таблице (CGFloat) tableView: (UITableView *) tableView heightForRowAtIndexPath: (NSIndexPath *) indexPath вы всегда возвращаете свое первое значение. вторая часть вашего кода никогда не будет вызвана, поэтому может быть причиной для crash.add условие в вышеуказанном делетете, например if (tableView == Hindi) возвращает hidi размер текста, если (tableView == English) возвращает английский textSize. Сообщите мне, если выше работает для вас. –