Mein UITableView fliegt mir gerade um die Ohren und ich verstehe nicht ganz, warum.
Ich unterscheide im Controller zwischen Section 1 und 2 für das Custom-Layout.
Der Fehler kommt nicht immer und wenn, dann nur beim scrollen und dann heißt es entweder:
oder auch manchmal:
Ich weiss nicht ansatzweise, wo das Problem liegt,
deshalb schmeiß ich hier auch gleich etwas brutal viel Code in den Thread.
Mache ich evtl. grundlegend etwas falsch bei meinen Customized-TableViewCells?
Hier mein cellForRowAtIndexPath:
Alles anzeigen
Und hier die zugehörige Methoden für meine Custom-Cell:
Alles anzeigen
Viele Grüße
Ich unterscheide im Controller zwischen Section 1 und 2 für das Custom-Layout.
Der Fehler kommt nicht immer und wenn, dann nur beim scrollen und dann heißt es entweder:
oder auch manchmal:
Ich weiss nicht ansatzweise, wo das Problem liegt,
deshalb schmeiß ich hier auch gleich etwas brutal viel Code in den Thread.
Mache ich evtl. grundlegend etwas falsch bei meinen Customized-TableViewCells?
Hier mein cellForRowAtIndexPath:
Quellcode
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- static NSString *CellIdentifier = @"Cell";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- if (cell == nil) {
- if (indexPath.section == 0)
- cell = [self getCellContentViewStart:CellIdentifier];
- else
- cell = [self getCellContentViewContinue:CellIdentifier];
- }
- // Configure the cell...
- if (indexPath.section == 0) {
- UILabel *lblTemp1 = (UILabel *)[cell viewWithTag:1];
- UILabel *lblTemp2 = (UILabel *)[cell viewWithTag:2];
- lblTemp1.text = @"neues Rätsel starten";
- lblTemp2.text = [NSString stringWithFormat:@"noch %i Rätsel nicht begonnen",[fileListArray count]-rowCount];
- }
- else {
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *loadFilePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:[myAnswers objectAtIndex:indexPath.row]];
- NSMutableArray *loadArray = [NSMutableArray arrayWithContentsOfFile:loadFilePath];
- UILabel *lblTemp1 = (UILabel *)[cell viewWithTag:1];
- UIProgressView *progressTemp = (UIProgressView *)[cell viewWithTag:2];
- UILabel *lblTemp2 = (UILabel *)[cell viewWithTag:3];
- UIButton *buttonTemp = (UIButton *)[cell viewWithTag:4];
- [buttonTemp addTarget:self action:@selector(delAlert:) forControlEvents:UIControlEventTouchUpInside];
- buttonTemp.tag = indexPath.row;
- lblTemp1.text = [NSString stringWithFormat:@"%@ Nr.%i",packName,indexPath.row+1];
- progressTemp.progress = [[loadArray objectAtIndex:2] floatValue];
- int percent = ([[loadArray objectAtIndex:2] floatValue] / [[loadArray objectAtIndex:1] floatValue])*100;
- lblTemp2.text = [NSString stringWithFormat:@"Gelöst: %i\%% Spielzeit: %@ min",percent,[loadArray objectAtIndex:3]];
- }
- return cell;
- }
Und hier die zugehörige Methoden für meine Custom-Cell:
Quellcode
- - (UITableViewCell *) getCellContentViewStart:(NSString *)CellIdentifier {
- CGRect CellFrame = CGRectMake(0, 0, 300, 70);
- CGRect Label1Frame = CGRectMake(10, 10, 290, 25);
- CGRect Label2Frame = CGRectMake(10, 33, 290, 25);
- UILabel *lblTemp;
- UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:CellFrame reuseIdentifier:CellIdentifier] autorelease];
- //Initialize Label with tag 1
- lblTemp = [[UILabel alloc] initWithFrame:Label1Frame];
- lblTemp.tag = 1;
- [cell.contentView addSubview:lblTemp];
- [lblTemp release];
- //Initialize Label with tag 2
- lblTemp = [[UILabel alloc] initWithFrame:Label2Frame];
- lblTemp.tag = 2;
- lblTemp.font = [UIFont boldSystemFontOfSize:12];
- lblTemp.textColor = [UIColor lightGrayColor];
- [cell.contentView addSubview:lblTemp];
- [lblTemp release];
- return cell;
- }
- - (UITableViewCell *) getCellContentViewContinue:(NSString *)CellIdentifier {
- CGRect CellFrame = CGRectMake(0, 0, 300, 80);
- CGRect Label1Frame = CGRectMake(55, 5, 290, 25);
- CGRect ProgressFrame = CGRectMake(55, 38, 210, 25);
- CGRect Label2Frame = CGRectMake(55, 44, 290, 25);
- CGRect ButtonFrame = CGRectMake(5, 5, 45, 70);
- UIButton *buttonTemp = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
- UILabel *lblTemp;
- UIProgressView *progressTemp;
- UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:CellFrame reuseIdentifier:CellIdentifier] autorelease];
- //Initialize Label with tag 1
- lblTemp = [[UILabel alloc] initWithFrame:Label1Frame];
- lblTemp.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
- lblTemp.tag = 1;
- lblTemp.font = [UIFont systemFontOfSize:14];
- [cell.contentView addSubview:lblTemp];
- [lblTemp release];
- //Initialize ProgrssBar with tag 2
- progressTemp = [[UIProgressView alloc] initWithFrame:ProgressFrame];
- progressTemp.tag = 2;
- [cell.contentView addSubview:progressTemp];
- [progressTemp release];
- //Initialize Label with tag 3
- lblTemp = [[UILabel alloc] initWithFrame:Label2Frame];
- lblTemp.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
- lblTemp.tag = 3;
- lblTemp.font = [UIFont boldSystemFontOfSize:12];
- lblTemp.textColor = [UIColor lightGrayColor];
- [cell.contentView addSubview:lblTemp];
- [lblTemp release];
- //Initialize Button with tag 4
- buttonTemp.tag = 4;
- [buttonTemp setTitle:@"reset" forState:UIControlStateNormal];
- buttonTemp.frame = ButtonFrame;
- buttonTemp.backgroundColor = [UIColor clearColor];
- [buttonTemp setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
- [buttonTemp setFont:[UIFont boldSystemFontOfSize:12]];
- [cell.contentView addSubview:buttonTemp];
- [buttonTemp release];
- return cell;
- }
Viele Grüße
dealloc {
[myLeak retain];
}
[myLeak retain];
}