Привет, у меня был этот вопрос, UITableView Не обновляется после того, как Modal View Controller отклоняет
Но, похоже, я не получил прямой ответ,
Может кто-нибудь ещепролить немного света?
Вот код.
FirstViewController.h
@interface FirstViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
NSMutableArray *routines;
IBOutlet UITableView *myTableView;
}
@property (nonatomic, retain) NSMutableArray *routines;
@property (nonatomic, retain) UITableView *myTableView;
- (IBAction)showNewEventViewController;
@ end
и его .m
#import "FirstViewController.h"
#import "NewEventViewController.h"
@implementation FirstViewController
@synthesize routines, myTableView;
- (void)viewWillAppear:(BOOL)animated{
[myTableView reloadData];
NSLog(@"Routines: %@", routines);
NSLog(@"refreshed!");
for(int i = 0; i < [routines count]; i++){
NSLog(@"%@", [routines objectAtIndex:i]);
}
}
- (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.routines = routines;
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"];
}
и контроллеры модального представления .h (NewEventViewController.h)
#import <UIKit/UIKit.h>
@interface NewEventViewController : UIViewController {
IBOutlet UITextField *RoutineTitle;
IBOutlet UITextField *RoutineInvolvment;
NSMutableArray *routines;
}
@property(nonatomic, retain) NSMutableArray *routines;
-(IBAction)done;
@end
и его .h
#import "NewEventViewController.h"
#import "FirstViewController.h"
@implementation NewEventViewController
@synthesize routines;
-(IBAction)done{
[routines addObject:RoutineTitle.text];
[self dismissModalViewControllerAnimated:YES];
NSLog(@"Routines: %@", routines);
}