views:

26

answers:

1

i'm trying to implement a system whereby the user is initially presented with a single tablecell, in a uitableview (grouped style), within a uinavigationview.

  ---------------
+ | add record  |
  ---------------

When they click on the cell, they are pushed onto a new screen where they fill in a few textviews (perhaps imbedded in a tableview's cells)

  ---------------
  | (name)      |
  ---------------
  | (phone num) |
  ---------------

Then when they go back, they can see the new record as well as the 'add record' cell.

  ---------------
  | record  1   |
  ---------------
+ | add record  |
  ---------------

(When they go into record 1 again there would be a delete button)

Is there any sample code or libraries which would achieve this?

+2  A: 

IMHO task is quite easy. You don't need any code examples for that. All you need is to understand how UITableView data source works and how UINavigationView works.

Read this 2 guides:

It should be more then enough to implement this feature.

In few words you should push UITableView into UINavigationController stack with "Add Record" cell. On selection event for this cell you should push another UITableView or your custom view. When user press "Done" button - you should save changed data into your model and pull current view from the UINavigationController stack. After that you should tell your first UITableView that model was changed and it will read it again.

Answer to the comment You should design your data structure. E.g. your model will be NSMutableArray of MyRecord objects. So you check in the tableView:cellForRowAtIndexPath:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath  {

UITableViewCell *cell = [tableView 
dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] 
        initWithStyle:UITableViewCellStyleDefault 
        reuseIdentifier:CellIdentifier] 
        autorelease];
}
if[recordsArray count] > 0 {
    // you have some records
    if(indexPath.row < [recordsArray count]) {
       MyRecord *record = [recordsArray objectAtIndex:indexPath.row];
       cell.textLabel.text = record.name;
    } else {
       // last cell is Add Record
       cell.textLabel.text = @"Add Record";
    }
} else {
cell.textLabel.text = @"Add Record";
}   
return cell;
}

That is just an idea. it can contains some stupid things (like 2 hardcoded @"Add Record") but idea should be clear

OgreSwamp
Thank for that. I'm familiar with pushing views and uitableviews etc, but I'm unclear about how to save and pass back data from the second table to my the initial table.... ?
cannyboy
See post update
OgreSwamp
Thanks. How would this record be passed from the second table to the first? I think I understand how it would be passed from 1st to 2nd view (create properties in the second view for the data, then set them in the first viewcontroller before pushing into the 2nd view).... but I'm not sure how to pass data from 2nd to 1st views.
cannyboy
If property will be "retain" type (not copy), then al changes made in 2nd view will be available in the 1st view because it will be same object. There are several ways to do that. @property (retain,nonatomic) is one of them.
OgreSwamp