Ich mache eine App mit einem UITableView, das ELCTextfieldCells verwendet. Für einige Zellen setze ich ein UISegmentedControl darüber und deaktiviere UITextField. „Ein Bild sagt mehr als tausend Worte“, also hier ist der Screenshot von dem, was ich bekomme, wenn ich zu diesem UITableView Stössel:Eigenartiges Verhalten von UISegmentedControl in UITableView
und nach dieser Zelle aus dem Bildschirm bewegen und es zurück setzen (im Grunde Nachladen) ich erhalte die folgende:
So gibt es zwei Probleme:
- UISegmentedControl nicht vi Wenn die Ansicht zum ersten Mal erscheint,
- Die Werte dieses UISegmentedControl werden irgendwo oben in die Zelle geschrieben;
einige Code, der irgendwie diese Zellen beeinflusst:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if ([[self.tableViewCellValues objectAtIndex:indexPath.row]rangeOfString:@"Gender"].location != NSNotFound || [[self.tableViewCellValues objectAtIndex:indexPath.row]rangeOfString:@"Still Active Employee"].location != NSNotFound) {
static NSString *CellIdentifier = @"CellWithSegmentedControl";
ELCTextfieldCell *cell = (ELCTextfieldCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[ELCTextfieldCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
[self configureCell:cell atIndexPath:indexPath];
UISegmentedControl *segmentedControl;
if ([cell.leftLabel.text rangeOfString:@"Gender"].location != NSNotFound) {
segmentedControl = [[UISegmentedControl alloc]initWithItems:[NSArray arrayWithObjects:@"Male", @"Female", nil]];
} else {
segmentedControl = [[UISegmentedControl alloc]initWithItems:[NSArray arrayWithObjects:@"Yes", @"No", nil]];
}
segmentedControl.frame = CGRectMake(215, 6, cell.rightTextField.frame.size.width, cell.rightTextField.frame.size.height - 10);
segmentedControl.tag = 26;
[segmentedControl addTarget:self action:@selector(segmentedControlHasChangedValue:) forControlEvents:UIControlEventValueChanged];
UIFont *font = [UIFont boldSystemFontOfSize:12.0f];
NSDictionary *attributes = [NSDictionary dictionaryWithObject:font forKey:UITextAttributeFont];
[segmentedControl setTitleTextAttributes:attributes forState:UIControlStateNormal];
[cell addSubview:segmentedControl];
[cell bringSubviewToFront:segmentedControl];
cell.rightTextField.text = @"";
cell.rightTextField.enabled = NO;
return cell;
}
//checks and other stuff for other cells
}
-(void)segmentedControlHasChangedValue:(id)sender {
NSLog(@"Nothing implemented here yet");
}
Jede Hilfe, wie kann ich das Problem beheben würde sehr geschätzt werden.
Danke
Vielleicht ist es das Problem der Wiederverwendung von Zellen. [This] (http://stackoverflow.com/a/9598341/641062) würde dir helfen. – Vignesh