2013-12-14 4 views
0

Я получаю сообщение об ошибке, которое я не понимаю, потому что я объявил это свойство. Прокомментировал ошибку в файле AllListViewController.m в методе cellForRowAtIndexPath:.Свойство не найдено в cellForRowAtIndexPath: метод

Вот файлы:

Checklist.h

#import <Foundation/Foundation.h> 

@interface Checklist : NSObject <NSCoding> 

@property (nonatomic, copy) NSString *name; 
@property (nonatomic, strong) NSMutableArray *items; 
@property (nonatomic, copy) NSString *iconName; 

-(int)countUncheckedItems; 

@end 

Checklist.m

#import "Checklist.h" 
#import "ChecklistItem.h" 

@implementation Checklist 


-(id)initWithCoder:(NSCoder *)aDecoder 
{ 
    if ((self = [super init])) { 
     self.name = [aDecoder decodeObjectForKey:@"Name"]; 
     self.items = [aDecoder decodeObjectForKey:@"Items"]; 
     self.iconName = [aDecoder decodeObjectForKey:@"IconName"]; 
    } 
    return self; 
} 

-(void)encodeWithCoder:(NSCoder *)aCoder 
{ 
    [aCoder encodeObject:self.name forKey:@"Name"]; 
    [aCoder encodeObject:self.items forKey:@"Items"]; 
    [aCoder encodeObject:self.iconName forKey:@"IconName"]; 
} 

-(id)init 
{ 
    if ((self = [super init])) { 
     self.items = [[NSMutableArray alloc] initWithCapacity:20]; 
     self.iconName = @"Appointments"; 
    } 
    return self; 
} 

-(int)countUncheckedItems 
{ 
    int count = 0; 
    for (ChecklistItem *item in self.items) { 
     if (!item.checked) { 
      count += 1; 
     } 
    } 
    return count; 
} 

-(NSComparisonResult)compare:(Checklist *)otherChecklist 
{ 
    return [self.name localizedStandardCompare:otherChecklist.name]; 
} 
@end 

AllListsViewController.h

#import <UIKit/UIKit.h> 
#import "ListDetailViewController.h" 

@class DataModel; 

@interface AllListsViewController : UITableViewController <ListDetailViewControllerDelegate, UINavigationControllerDelegate> 

@property (nonatomic, strong) DataModel *dataModel; 

@end 

AllListsViewController.m

#import "AllListsViewController.h" 
#import "Checklist.h" 
#import "ChecklistViewController.h" 
#import "ChecklistItem.h" 
#import "DataModel.h" 

@interface AllListsViewController() 

@end 

@implementation AllListsViewController 

- (id)initWithStyle:(UITableViewStyle)style 
{ 
    self = [super initWithStyle:style]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    // Uncomment the following line to preserve selection between presentations. 
    // self.clearsSelectionOnViewWillAppear = NO; 

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller. 
    // self.navigationItem.rightBarButtonItem = self.editButtonItem; 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [self.dataModel setIndexOfSelectedChecklist:indexPath.row]; 

    Checklist *checklist = self.dataModel.lists[indexPath.row]; 
    [self performSegueWithIdentifier:@"ShowChecklist" sender:checklist]; 
} 

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    if ([segue.identifier isEqualToString:@"ShowChecklist"]) { 
     ChecklistViewController *controller = segue.destinationViewController; 
     controller.checklist = sender; 
    } 
    else if ([segue.identifier isEqualToString:@"AddChecklist"]) { 
     UINavigationController *navigationController = segue.destinationViewController; 
     ListDetailViewController *controller = (ListDetailViewController *)navigationController.topViewController; 

     controller.delegate = self; 
     controller.checklistToEdit = nil; 
    } 
} 

-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath 
{ 
    UINavigationController *navigationController = [self.storyboard instantiateViewControllerWithIdentifier:@"ListNavigationController"]; 

    ListDetailViewController *controller = (ListDetailViewController *)navigationController.topViewController; 

    controller.delegate = self; 

    Checklist *checklist = self.dataModel.lists[indexPath.row]; 
    controller.checklistToEdit = checklist; 

    [self presentViewController:navigationController animated:YES completion:nil]; 
} 

#pragma mark - Table view data source 


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 

    // Return the number of rows in the section. 
    return [self.dataModel.lists count]; 
} 

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [self.dataModel.lists removeObjectAtIndex:indexPath.row]; 

    NSArray *indexPaths = @[indexPath]; 
    [tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationAutomatic]; 
} 

- (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]; 
     cell.imageView.image = [UIImage imageNamed:Checklist.iconName]; /* Use of undeclared identifier; did you mean 'Checklist'? or Property 'iconName' not found on object of type 'Checklist'*/ 
     return cell; 
    } 

    Checklist *checklist = self.dataModel.lists[indexPath.row]; 
    cell.textLabel.text = checklist.name; 
    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; 

    cell.detailTextLabel.text = [NSString stringWithFormat:@"%d Remaining", [checklist countUncheckedItems]]; 

    int count = [checklist countUncheckedItems]; 
    if ([checklist.items count] == 0) { 
     cell.detailTextLabel.text = @"(No Items)"; 
    } else if (count == 0) { 
     cell.detailTextLabel.text = @"All Done"; 
    } else { 
     cell.detailTextLabel.text = [NSString stringWithFormat:@"%d Remaining", count]; 
    } 

    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:@[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 - Navigation 

// In a story board-based application, you will often want to do a little preparation before navigation 
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    // Get the new view controller using [segue destinationViewController]. 
    // Pass the selected object to the new view controller. 
} 

*/ 

-(void)listDetailViewControllerDidCancel:(ListDetailViewController *)controller 
{ 
    [self dismissViewControllerAnimated:YES completion:nil]; 
} 

-(void)listDetailViewController:(ListDetailViewController *)controller didFinishAddingChecklist:(Checklist *)checklist 
{ 
    [self.dataModel.lists addObject:checklist]; 

    [self.dataModel sortChecklists]; 
    [self.tableView reloadData]; 

    [self dismissViewControllerAnimated:YES completion:nil]; 

} 

-(void)listDetailViewController:(ListDetailViewController *)controller didFinishEditingChecklist:(Checklist *)checklist 
{ 
    [self.dataModel sortChecklists]; 
    [self.tableView reloadData]; 

    [self dismissViewControllerAnimated:YES completion:nil]; 
} 

-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated 
{ 
    if(viewController == self) { 
     [self.dataModel setIndexOfSelectedChecklist:-1]; 
    } 
} 

-(void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 
    [self.tableView reloadData]; 
} 



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

    self.navigationController.delegate = self; 

    NSInteger index = [self.dataModel indexOfSelectedChecklist]; 

    if(index >= 0 && index < [self.dataModel.lists count]) { 
     Checklist *checklist = self.dataModel.lists[index]; 
     [self performSegueWithIdentifier:@"ShowChecklist" sender:checklist]; 
    } 
} 

@end 

ответ

1

Вы не указали переменную «Контрольный список» &, пытаясь получить доступ к значению «iconName». Фактически вы пытаетесь получить к нему доступ непосредственно через имя класса.

Я вижу, что вы создали экземпляр, если «Контрольный список» несколько строк вниз. Поэтому лучше создать этот экземпляр перед использованием Checklist.iconName

Может быть в начале функции после создания CellIdentifier.

Checklist *checklist = self.dataModel.lists[indexPath.row]; 
    cell.imageView.image = [UIImage imageNamed:checklist.iconName]; /* Use of undeclared identifier; did you mean 'Checklist'? or Property 'iconName' not found on object of type 'Checklist'*/ 
     return cell; 
    } 

В соответствии с вашим кодом, «Контрольный список» Ваше имя класса, в то время как экземпляр начинается с малого «с» как «контрольный список». Возможно, вы тоже смутились.

Надеюсь, что это поможет.

+0

спасибо. Я переместил эту строку, где я объявил контрольный список и переместил его, и это сработало. – pdenlinger

Смежные вопросы