2016-05-19 5 views
-3

enter code here [image youtube du même code] [1] Je continue à obtenir une erreur avec mon code où il est ditsyntaxe Objective-C erreur - inattendu "@"/incapable de résoudre les problèmes

"inattendu" @ » dans le programme et aussi manquant « @end »

Si vous regardez le code ci-dessous la @end est là, mais cependant que je retaper la réponse est la même « @end manquant »

Voici le code complet

#import "MasterViewController.h" 
#import "DetailViewController.h" 

@interface MasterViewController() 

@end 

@implementation MasterViewController 
-(NSMutableArray *) objects 

{ 
if (!_objects){ 
_objects =[[NSMutableArray alloc]init]; 
} 
return _objects; 
} 

-(NSMutableArray *) results 
{ 
if (!_results) { 
_results =[[NSMutableArray alloc]init]; 
} 
return _results; 
} 
-(void)viewDidLoad 
{ 
[super viewDidLoad]; 

[self.objects addObject:@"Tabebuia yellow"]; 
[self.objects addObject:@"Prunus armeniaca"]; 
[self.objects addObject:@"Tabebuia rosea"]; 

} 
-(void)didReceiveMemoryWarning { 
[super didReceiveMemoryWarning]; 
// Dispose of any resources that can be recreated. 
} 
-(void) searchThroughData 
{ 
self.results= nil; 
NSPredicate * resultsPredicate = [NSPredicate predicateWithFormat:@"SELF contains [search]%@", self.searchBar.text]; 
self. results = [[ self.objects filteredArrayUsingPredicate:resultsPredicate]mutableCopy]; 
} 
-(void) searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText 
{ 
[self searchThroughData]; 
} 
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
return 1; 
} 

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
if (tableView == self.tableView) 
{ 
return self.objects.count; 

}else{ 

[self searchThroughData]; 
return self.results.count; 
} 
} 
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString *CellIdentifier = @"Cell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

if (!cell) 
{ 
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier: CellIdentifier]; 
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
} 

if (tableView == self.tableView){ 
cell.textLabel.text = self.objects[indexPath.row]; 

} else { 
cell.textLabel.text = self.results[indexPath.row]; 

} 
return cell; 
} 

    -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 
if (self.searchController.isActive) 
{ 

[self performSegueWithIdentifier:@"Showdetail" sender:self]; 

} 

-(void) PrepareForSegue:(UIStoryboardSegue *) segue sender:(id) sender 


if ([[ segue identifier] isEqualToString:@"ShowDetail"]) { 

NSString *object = nil; 
NSIndexPath *Indexpath = nil; 

if (self.UISearchController.isActive) 
{UISearchController 
    Indexpath = [[ self.searchController searchResultsTableView]indexPathForSelectedRow]; 
    object = self.results [Indexpath.row]; 
}else{ 

     Indexpath = [self.tableView indexPathForSelectedRow]; 
object = [[self.objects [Indexpath.row]; 



    [segue destinationViewController] setDetailLabelContents:object]; 
}} 

@end 

Répondre

3
  1. Vous avez pas de clôture } à la fin de la méthode prepareForSegue:sender:. Le formatage et l'indentation le font clairement.
  2. Vous avez du code flottant juste à l'extérieur d'une méthode (les lignes avant que la méthode tableView:didSelectRowAtIndexPath:.

Il doit y avoir un appariement approprié des besoins à l'intérieur des méthodes ou des fonctions { et } et le code.