Passing data between view
Passing data between view
- Subject: Passing data between view
- From: Kévin Vavelin <email@hidden>
- Date: Sat, 01 Sep 2012 16:09:38 +0200
Hi there,
I'm pretty confuse right now 'cause I can't pass my data to my masterView and I don't know why… I have a master detail view, I don't want to use the detail view so I delete it.
I create a new view with a textField and I want to do this action :
When I hit the + button on the top right of my masterView, I open my second View with my textField and a validate button.
Enter a name on the textField and when I hit the validate button, go back to my masterView and adding a row with my textField value as title.
I wrote this but it doesn't work :/ :
//MasterView.h
@interface MasterViewController : UITableViewController
{
NSString *nameCategory;
}
@property(nonatomic, retain)NSString *nameCategory;
@property(nonatomic, retain)NSMutableArray *categoryArray;
@end
//MasterView.m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewCategorie:)] autorelease];
self.navigationItem.rightBarButtonItem = addButton;
self.navigationItem.title = @"Budget";
}
- (void)insertNewCategorie:(id)sender
{
[self performSegueWithIdentifier:@"Add new category" sender:self];
}
#pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _categoryArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
cell.textLabel.text = [_categoryArray objectAtIndex:indexPath.row];
NSLog(@"%@", [_categoryArray objectAtIndex:indexPath.row]);
// NSDate *object = [_objects objectAtIndex:indexPath.row];
// cell.textLabel.text = [object description];
return cell;
}
//AddViewController.h
@interface AddViewController : UIViewController <UITextFieldDelegate>
{
NSString *nameCategory;
}
@property(nonatomic, retain)NSString *nameCategory;
@property (retain, nonatomic) IBOutlet UITextField *nameTextField;
- (IBAction)addName:(id)sender;
@end
//AddViewController.m
- (IBAction)addName:(id)sender
{
MasterViewController *parentView = [[MasterViewController alloc] init];
[parentView setNameCategory:nameTextField.text];
[parentView.categoryArray addObject:nameTextField.text];
NSLog(@"%@", parentView.nameCategory);
NSLog(@"%@", parentView.categoryArray);
[self dismissModalViewControllerAnimated:YES];
}
I try [parentView.categoryArray insertObject:nameTextField.text atIndex:0]; and it doesn't work too.
I don't understand well how to pass data with tutorial so i'm pretty confuse right now :/
If you can help me :)
Thanks in advance.
Vavelin Kévin
Twitter | Blog | LinkedIn
Entrepreneur
Developer OS X / iOS
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden