views:

136

answers:

1

I'm loading a UITableViewCell that contains two tagged labels. The user will leave the current view, containing the following code and go to another view. A name value is set there and the user comes back to this view (code below). I assign the name they set in the other view to the name label. That works but I get a new label misaligned on top of my other labels. It seems I'm keep two versions of this cell. Not quite sure. Any suggestions on what might be causing that sort of behavior?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = nil;
if(indexPath.section == 0)
{ 
 cell = [tableView dequeueReusableCellWithIdentifier:@"CellNameIdentifier"];
 if (cell == nil) {
  [[NSBundle mainBundle] loadNibNamed:@"CellentName" owner:self options:nil];
  cell = cellName;
  //self.cellName = nil;
 }
}
return cell;
}
- (void)viewDidAppear:(BOOL)animated {
UILabel *startdate = (UILabel *)[cellName viewWithTag:1];
startdate.text = aName;
[super viewDidAppear:animated];
}
+1  A: 

From the look of this code it is less likely that you are getting "a new label misaligned on top of my other labels" and more like the drawing is failing to repaint on top of things properly. To make this work, you can try calling [tableView reloadData] or using an observer, but I think there is a better way.

You should be able to pass the object into your other view, modify the object (instead of the label) and move the data around that way. In other words on the table view, it loads the objects, and inside of cellForRowAtIndexPath it loads the cells and sets the label names using the object data. Push in the second view and pass the object as a property. Manipulate this property all you want on that screen and when you pop the view, there is no special logic. The first table view again displays whatever is saved inside that object you were manipulating.

slf
I'm not following. aName comes from my appdelegate class. So it is always available as an instance. I shouldn't need to pass object data to the second view in that case right? I think a change is needed in cellForRowAtIndexPath for, " displays whatever is saved inside that object" to work right?
4thSpace
Have a look at the SQLiteBooks apple example project for a detailed code example of passing and manipulating objects as properties.
slf