2012-04-07 3 views
0

내가 DictAddSubSecondCell라는 UIViewController에 제시하는 다음과 같은 방법을 사용 닫으면있는 tableView를 다시로드하는 방법 : 나는 DictAddSubSecondCell에서 버튼을 클릭하면UIViewController에

// UIViewControler 1 
- (IBAction)addWord:(id)sender{ 
dictAddSubSecondCellController = [[DictAddSubSecondCell alloc] initWithNibName:@"DictAddSubSecondCell" bundle:nil]; 
[self presentModalViewController:dictAddSubSecondCellController animated:YES]; 
[dictAddSubSecondCellController release]; 
} 

을과 :

- (IBAction)dismissAction:(id)sender{ 
[self dismissModalViewControllerAnimated:YES]; 
} 

UIViewControler에있는 tableView 1은 데이터를 다시로드하지 않았지만 viewWillApear 메서드에 메서드를 추가했습니다.

[self.table reloadData]; 

하지만 여전히 작동하지 않습니다. 나는 이것에 대해 전혀 모른다. 저에게 어떤 제안이 있습니까? 감사.

// 
// DictAddSubSecond.m 
// 
// Created by Samuel Armstrong on 4/8/12. 
// Copyright 2012 __MyCompanyName__. All rights reserved. 
// 

#import "DictAddSubSecond.h" 
#import "DictionaryList.h" 

@implementation DictAddSubSecond 
@synthesize dictList, table, editButton; 
@synthesize dictAddSubSecondCellController; 

- (IBAction)addWord:(id)sender 
{ 
    dictAddSubSecondCellController = [[DictAddSubSecondCell alloc] initWithNibName:@"DictAddSubSecondCell" bundle:nil]; 
    [self presentModalViewController:dictAddSubSecondCellController animated:YES]; 
    [dictAddSubSecondCellController release]; 
} 

- (IBAction)toggleEdit { 
    [self.table setEditing:!self.table.editing animated:YES]; 

    if (self.table.editing) { 
     [editButton setTitle:@"Done"]; 
     [editButton setStyle:UIBarButtonItemStyleDone]; 
    } 
    else { 
     [editButton setTitle:@"Edit"]; 
     [editButton setStyle:UIBarButtonItemStyleBordered]; 

    } 
} 

- (IBAction)dismissAction:(id)sender 
{ 
    [self dismissModalViewControllerAnimated:NO]; 
} 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (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. 
} 

#pragma mark - View lifecycle 

- (void)refreshTableData 
{ 
    NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 
    NSString *file = [path stringByAppendingPathComponent:@"dictWithWords.tmp"]; 
    if (dictList == nil) { 
     NSMutableArray *array = [[NSMutableArray alloc] initWithContentsOfFile:file]; 
     if ([array objectAtIndex:0] != nil) { 
      dictList = [[NSMutableArray alloc] initWithCapacity:1]; 
      self.dictList = array; 
      [array release]; 
     } 
     else 
     { 
      dictList = [[NSMutableArray alloc] initWithCapacity:1]; 
     } 
    } 
    [self.table reloadData]; 

} 

- (void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 

    [self refreshTableData]; 
} 

- (void)someMethodToReloadTable:(NSNotification *)notification 
{ 
    [table reloadData]; 
} 


- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(someMethodToReloadTable) name:@"reloadTable" object:nil]; 


} 

- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"reloadTable" object:nil]; 


} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 




#pragma mark - 
#pragma mark Table View Data Source Methods 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return [dictList count]; 
} 


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *MoveMeCellIdentifier = @"MoveMeCellIdentifier"; 
    UITableViewCell *cell = [self.table dequeueReusableCellWithIdentifier:MoveMeCellIdentifier]; 

    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:MoveMeCellIdentifier] autorelease]; 

     //A Boolean value that determines whether the cell shows the reordering control. 
     cell.showsReorderControl = YES; 

    } 
    NSUInteger row = [indexPath row]; 

    cell.textLabel.text = [dictList objectAtIndex:row]; 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    return cell; 
} 

#pragma mark - 
#pragma mark Table View Delegate Methods 
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSUInteger row = [indexPath row]; 
    [self.dictList removeObjectAtIndex:row]; 
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] 
        withRowAnimation:UITableViewRowAnimationMiddle]; 
} 


- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return UITableViewCellEditingStyleDelete; 
} 




// Asks the data source whether a given row can be moved to another location in the table view. 
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return YES; 
} 


//Tells the data source to move a row at a specific location in the table view to another location. 
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath 
{ 
    NSUInteger fromRow = [fromIndexPath row]; 
    NSUInteger toRow = [toIndexPath row]; 

    id object = [[dictList objectAtIndex:fromRow] retain]; 
    [dictList removeObjectAtIndex:fromRow]; 
    [dictList insertObject:object atIndex:toRow]; 
    [object release]; 
} 


@end 
+0

로직이 합리적인 것처럼 보입니다. 로그 메시지 나 디버거 중 하나를 사용하여 두 가지를 확인할 수 있습니다 :'[self.table reloadData]'가 실제로 거기에서 호출되고 있으며, 그렇다면 델리게이트 메소드 (예 :'numberOfRowsInSection : ')? –

+0

DictAddSubSecondCell의 Documents/폴더에서 파일 (writeTOfile 메서드를 사용하여 NSArray 인스턴스)을 수정했으며 UIViewControler 1에 수정 된 결과를 표시하려고합니다. 이제 UIViewControler 1을 다시로드하면 새 결과 만 표시됩니다. – Samblg

+0

즉, TableView는 modalview가 – Samblg

답변

1

viewDidAppear: 대신 viewWillAppear:에 전화하십시오 :

여기의 UIViewController 1의 전체 소스 코드입니다.

+0

을 기각 한 후 다시로드되지 않음을 의미합니다. – Samblg

+0

viewDidAppear :이 호출되고 있습니까? 그 안에 NSLog 문을 넣어 확인하십시오. 위임 메서드를 잘못 입력하는 것은 쉽습니다. 호출해야하는 정확한 작업이어야합니다. –

+0

- (void) viewWillAppear : (BOOL) 애니메이션을 닫을 때 애니메이션이 호출됩니다. – Samblg

관련 문제