Hello All.
This is my app im working on. http://twitpic.com/yrzpo and it has a modal view that i want to let the user app things to the routines list. http://twitpic.com/yrzs3
The table view on the first page, has a data source of a NSMutableArray. On the second page, i would like to add to that array, by typing in the top text field, so when the modal view pops down, what was typed in the the field was added to the list.
Surely there is a way to do this.
Keep in mind, that my template for this app was a tab bar application. FirstViewController.h
@interface FirstViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
NSMutableArray *routines;
}
@property (nonatomic, retain) NSMutableArray *routines;
- (IBAction)showNewEventViewController;
@end
FirstViewController.m
#import "FirstViewController.h"
#import "NewEventViewController.h"
@implementation FirstViewController
@synthesize routines;
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [routines count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell...
NSString *cellValue = [routines objectAtIndex:indexPath.row];
[cell.textLabel setText:cellValue];
return cell;
}
- (IBAction)showNewEventViewController {
NewEventViewController *controller = [[NewEventViewController alloc] initWithNibName:@"NewEventView" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:controller animated:YES];
[controller release];
}
- (void)viewDidLoad {
routines = [[NSMutableArray alloc] init];
[routines addObject:@"Hello"];
[routines addObject:@"Temp"];
[routines addObject:@"Temp2"];
[routines addObject:@"Temp3"];
[routines addObject:@"Temp4"];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[routines release];
[super dealloc];
}
@end
NewEventViewController.h
#import <UIKit/UIKit.h>
@interface NewEventViewController : UIViewController {
IBOutlet UITextField *RoutineTitle;
IBOutlet UITextField *RoutineInvolvment;
}
-(IBAction)done;
@end
NewEventViewController.m
#import "NewEventViewController.h"
#import "FirstViewController.h"
@implementation NewEventViewController
-(IBAction)done{
[RoutineTitle resignFirstResponder];
[RoutineInvolvment resignFirstResponder];
NSString *myString = RoutineTitle.text;
FirstViewController *FirstView = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
NSMutableArray *routines;
NSLog(@"Log the String: %@", myString);
FirstView.routines = routines;
[routines addObject:myString];
NSLog(@"Log Array :%@", FirstView.routines);
[self dismissModalViewControllerAnimated:YES];
}
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end
I urge anyone who can, please have a look at the code, and tell me what I am doing wrong. Im new to this game, ( and esp to apps that are not a single view)
I hope I have made this clear.
Thanks a lot in advance.
Sam
PS. my last few questions are all culminated in this one, for everyones ease.
Thanks.