2010-12-17 25 views
0

私のアプリケーションでアンロードビューの問題。アプリがクラッシュする

2つの行を持つテーブルビューがあります。

  1. 日付。
  2. 市。

選択日付...私は十分に良い作業EventViewControllerビューをロード...

戻って私のテーブルビューと選択した都市に私のアプリの取得が

を墜落なったときに、私は任意の表示されません私のコンソールのもの。そのメッセージは表示されません。

実装のために何をすべきか...ここ

がコードです....

ザ・......

が、私のアプリがクラッシュします...

#import "SearchViewController.h" 
    #import "SearchDetailViewController.h" 
    #import "EventViewController.h" 

    @implementation SearchViewController 
    @synthesize searchListArray; 
    /* 
    // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. 
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { 
     if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { 
      // Custom initialization 
     } 
     return self; 
    } 
    */ 


    // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 
    - (void)viewDidLoad { 
     [super viewDidLoad]; 
     UIBarButtonItem *barButton=[[UIBarButtonItem alloc]initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil]; 
     self.navigationItem.backBarButtonItem=barButton; 
     [barButton release]; 
     searchListArray =[[NSMutableArray alloc]init]; 
     [searchListArray addObject:@"City"]; 
     [searchListArray addObject:@"Populair"]; 
     [searchListArray addObject:@"Date"]; 
    } 

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
      // Return the number of sections. 
     return 1; 
    } 

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
      // Return the number of rows in the section. 
     return [searchListArray count]; 
    } 

     // Customize the appearance of table view cells. 
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
     static NSString *CellIdentifier = @"Cell"; 

     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if (cell == nil) { 
      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 
      cell.selectionStyle= UITableViewCellSelectionStyleBlue; 
    //  cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator; 
      cell.backgroundColor=[UIColor blueColor]; 
      cell.textLabel.text=[searchListArray objectAtIndex:indexPath.row]; 
      switch (indexPath.row) { 
       case 0: 
        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator; 
        break; 
        case 2: 
        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator; 
        break; 

       default: 
        break; 

      } 
     } 
     return cell; 

    } 
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 

     switch (indexPath.row) { 
      case 0: 
       NSLog(@"searchdetailedview"); 
       SearchDetailViewController *searchDetailViewController = [[SearchDetailViewController alloc] initWithNibName:@"SearchDetailViewController" bundle:nil]; 
       [self.navigationController pushViewController:searchDetailViewController animated:YES]; 
        // self.navigationItem.title = @"Back"; 
       [searchDetailViewController release]; 
       searchDetailViewController=nil; 
       break; 
       case 2: 
       NSLog(@"eventviewController"); 

       EventViewController *eventViewController=[[EventViewController alloc]initWithNibName:@"EventViewController" bundle:nil]; 
       [self.navigationController pushViewController:eventViewController animated:YES]; 
       [eventViewController release]; 
       eventViewController=nil; 
       break; 
      default: 
       break; 
     } 
    } 



    /* 
    // Override to allow orientations other than the default portrait orientation. 
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
     // Return YES for supported orientations 
     return (interfaceOrientation == UIInterfaceOrientationPortrait); 
    } 
    */ 



    - (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 { 
     [super viewDidUnload]; 
     // Release any retained subviews of the main view. 
     // e.g. self.myOutlet = nil; 
    } 


    - (void)dealloc { 
     [searchListArray release]; 
     [super dealloc]; 
    } 

EventViewController

#import "EventViewController.h" 

    @implementation EventViewController 
    @synthesize eventsList; 
    @synthesize eventStore; 
    @synthesize defaultCalendar; 
    @synthesize detailViewController; 

    #pragma mark - 
    #pragma mark View lifecycle 


    - (void)viewDidLoad { 
     [super viewDidLoad]; 
     [email protected]"Event List"; 
     self.eventStore=[[EKEventStore alloc]init]; 
     self.eventsList=[[NSMutableArray alloc]initWithArray:0]; 
     self.defaultCalendar=[self.eventStore defaultCalendarForNewEvents]; 
      // Uncomment the following line to display an Edit button in the navigation bar for this view controller. 
     UIBarButtonItem *addButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: 
              UIBarButtonSystemItemAdd target:self action:@selector(addEvent:)]; 
     self.navigationItem.rightBarButtonItem = addButtonItem; 
     [addButtonItem release]; 
     self.navigationController.delegate = self; 
     [self.eventsList addObjectsFromArray:[self fetchEventsForToday]]; 
     [self.tableView reloadData]; 
    } 

    - (IBAction) addEvent:(id)sender{ 
     EKEventEditViewController *addController = [[EKEventEditViewController alloc] initWithNibName:nil bundle:nil]; 
      // set the addController's event store to the current event store. 
     addController.eventStore = self.eventStore; 
      // present EventsAddViewController as a modal view controller 
     [self presentModalViewController:addController animated:YES]; 
     addController.editViewDelegate = self; 
     [addController release]; 
    } 

    - (NSArray *) fetchEventsForToday{ 

     NSDate *startDate = [NSDate date]; 
      // endDate is 1 day = 60*60*24 seconds = 86400 seconds from startDate 
     NSDate *endDate = [NSDate dateWithTimeIntervalSinceNow:86400]; 
      // Create the predicate. Pass it the default calendar. 
     NSArray *calendarArray = [NSArray arrayWithObject:defaultCalendar]; 
     NSPredicate *predicate = [self.eventStore predicateForEventsWithStartDate:startDate endDate:endDate 
                     calendars:calendarArray]; 
      // Fetch all events that match the predicate. 
     NSArray *events = [self.eventStore eventsMatchingPredicate:predicate]; 
     return events; 
    } 

    - (void)viewWillAppear:(BOOL)animated { 
      // [super viewWillAppear:animated]; 
     [self.tableView deselectRowAtIndexPath:self.tableView.indexPathForSelectedRow animated:NO]; 

    } 


    /* 
    - (void)viewDidAppear:(BOOL)animated { 
     [super viewDidAppear:animated]; 
    } 
    */ 
    /* 
    - (void)viewWillDisappear:(BOOL)animated { 
     [super viewWillDisappear:animated]; 
    } 
    */ 
    /* 
    - (void)viewDidDisappear:(BOOL)animated { 
     [super viewDidDisappear:animated]; 
    } 
    */ 

    // Override to allow orientations other than the default portrait orientation. 
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
     // Return YES for supported orientations 
     return (interfaceOrientation == UIInterfaceOrientationPortrait); 
    } 



    #pragma mark - 
    #pragma mark Table view data source 

    //- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    // // Return the number of sections. 
    // // return <#number of sections#>; 
    //} 


    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
     // Return the number of rows in the section. 
     return [eventsList count]; 
    } 


    // Customize the appearance of table view cells. 
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

     static NSString *CellIdentifier = @"Cell"; 
     UITableViewCellAccessoryType editableCellAccessoryType =UITableViewCellAccessoryDisclosureIndicator; 


     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if (cell == nil) { 
      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
     } 
     cell.accessoryType=editableCellAccessoryType; 
     cell.textLabel.text=[[self.eventsList objectAtIndex:indexPath.row]title]; 
     // Configure the cell... 

     return cell; 
    } 


    /* 
    // Override to support conditional editing of the table view. 
    - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 
     // Return NO if you do not want the specified item to be editable. 
     return YES; 
    } 
    */ 


    /* 
    // Override to support editing the table view. 
    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 

     if (editingStyle == UITableViewCellEditingStyleDelete) { 
      // Delete the row from the data source 
      [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
     } 
     else if (editingStyle == UITableViewCellEditingStyleInsert) { 
      // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view 
     } 
    } 
    */ 


    /* 
    // Override to support rearranging the table view. 
    - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { 
    } 
    */ 


    /* 
    // Override to support conditional rearranging of the table view. 
    - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { 
     // Return NO if you do not want the item to be re-orderable. 
     return YES; 
    } 
    */ 


    #pragma mark - 
    #pragma mark Table view delegate 

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    // Navigation logic may go here. Create and push another view controller. 
    // Upon selecting an event, create an EKEventViewController to display the event. 
     self.detailViewController = [[EKEventViewController alloc] initWithNibName:nil bundle:nil];   
     detailViewController.event = [self.eventsList objectAtIndex:indexPath.row]; 
    // Allow event editing. 
     detailViewController.allowsEditing = YES; 
    // Push detailViewController onto the navigation controller stack 
    // If the underlying event gets deleted, detailViewController will remove itself from 
    // the stack and clear its event property. 
     [self.navigationController pushViewController:detailViewController animated:YES]; 

    } 


    #pragma mark - 
    #pragma mark Navigation Controller delegate 

    - (void)navigationController:(UINavigationController *)navigationController 
      willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{ 
     if (viewController == self && self.detailViewController.event.title == NULL) { 
      [self.eventsList removeObject:self.detailViewController.event]; 
      [self.tableView reloadData]; 
     } 
    } 

    - (void)eventEditViewController:(EKEventEditViewController *)controller 
       didCompleteWithAction:(EKEventEditViewAction)action{ 
     NSError *error=nil; 
     EKEvent *thisEvent=controller.event; 
     switch (action) { 
      case EKEventEditViewActionCanceled: 
       break; 
      case EKEventEditViewActionSaved: 
       if (self.defaultCalendar ==thisEvent.calendar) { 
        [self.eventsList addObject:thisEvent]; 
       } 
       [controller.eventStore saveEvent:controller.event span:EKSpanThisEvent error:&error]; 
       [self.tableView reloadData]; 
       break; 
      case EKEventEditViewActionDeleted: 
       if (self.defaultCalendar == thisEvent.calendar) { 
        [self.eventsList removeObject:thisEvent]; 
       } 
       [controller.eventStore removeEvent:thisEvent span:EKSpanThisEvent error:&error]; 
       [self.tableView reloadData]; 
       break; 

      default: 
       break; 
     } 
     [controller dismissModalViewControllerAnimated:YES]; 
    } 

    - (EKCalendar *)eventEditViewControllerDefaultCalendarForNewEvents:(EKEventEditViewController *)controller{ 
     EKCalendar *calendarForEdit=self.defaultCalendar; 
     return calendarForEdit; 
    } 
    #pragma mark - 
    #pragma mark Memory management 

    - (void)didReceiveMemoryWarning { 
     // Releases the view if it doesn't have a superview. 
     [super didReceiveMemoryWarning]; 

     // Relinquish ownership any cached data, images, etc that aren't in use. 
    } 

    - (void)viewDidUnload { 
     // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand. 
     // For example: self.myOutlet = nil; 
     self.eventsList = nil; 
     [self.detailViewController release]; 

    } 


    - (void)dealloc { 
     [super dealloc]; 
    } 

これは私がやったことです....助けてください。

@thanks事前に。

+0

あなたのテーブルは現在フリーオブジェクトです。ビューはフリーオブジェクトです。問題を理解するためのコードをいくつか与えてください。 – Ishu

答えて

1

次の手順で行ってください。

1)を押してビルドとデバッグ(ビルド - >ビルドとデバッグ - 2)にブレークポイントを)あなたのデバッガ 3を開きます)クラッシュ 4を作成します)さて、に行きますデバッガを起動して左側の黒い項目を探します 5)この項目を押すと、アプリケーションがクラッシュする箇所が見つかります

これを実行した場合は、アプリケーションがクラッシュする場所を書き留めてください。 。そしておそらく、あなたはエラーを見つけるでしょう。

1

あなたの問題は、[EventViewController viewDidLoad]のself.navigationController.delegate = self;になる可能性があると思います。戻るボタンを押すと、EventViewControllerは解放されますが、navigationControllerは引き続きそれがそのデリゲートであると考えます。したがって、次のView Controllerを開いても問題ないかどうかを尋ねると、解放されたオブジェクトのメソッドが呼び出され、クラッシュが発生します。

+0

@ughovgfhw ...再生していただきありがとうございます。 –

関連する問題