i am new to ios programming;
I write an app to show a recipe list in a UITableView
and after select a row, row title parse to a UITextField
in detail view.
question: what can i do for save title change in detailview to table view (i use storyboard)?
this is my code :
NViewController.m :
- (void)viewDidLoad
{
[super viewDidLoad];
recipes = [NSArray arrayWithObjects:@"Egg Benedict", @"Mushroom Risotto", @"Full Breakfast", nil];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"RecipeCell";
MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[MyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.lblName.text = [recipes objectAtIndex:indexPath.row];
return cell;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"showRecipeDetail"]) {
NSIndexPath *indexPath = [self._tableView indexPathForSelectedRow];
NDetailViewController *destViewController = segue.destinationViewController;
destViewController.selectedRowTitle = [recipes objectAtIndex:indexPath.row];
}
}
NDetailViewController.m :
@interface NDetailViewController ()
@property (weak, nonatomic) IBOutlet UITextField *txtDetailText;
@end
@implementation NDetailViewController
@synthesize selectedRowTitle;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.txtDetailText.text = selectedRowTitle;
}