目标C:属性错误

时间:2010-10-16 04:36:52

标签: iphone objective-c

我在为代码的NSArray属性设置值时遇到了一些错误。我将向您发送de代码和调试器输出。


@interface RootViewController : UITableViewController {
 @private
 NSArray* regioesArray;
// NSString *str;
// NSArray *ar;
}

@property(nonatomic, retain) NSArray *regioesArray;

@implementation RootViewController

@synthesize regioesArray;
//@synthesize str;
//@synthesize ar;

- (void)viewDidLoad {
 [super viewDidLoad];

 //Set Title
 self.title = @"Regiões";
 self.regioesArray = nil;
}

- (void)viewDidUnload {
    self.regioesArray = nil;
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
 return 2;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
 if(section == 0 && self.regioesArray != nil){
  return [regioesArray count];
 }else {
  return 0;
 }
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

 static NSString *MyIdentifier = @"MyIdentifier";

 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
 if (cell == nil) {
  cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
 }

 // Set up the cell
 Zona *zona = (Zona *)[regioesArray objectAtIndex:indexPath.row];
 cell.text = [zona nome];
 [cell.contentView addSubview: [self getDetailDiscolosureIndicatorForIndexPath: indexPath]]; 
 [zona release];

 return cell;
}


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


/*
 Override if you support editing the list
- (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:YES];
 } 
 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 if you support conditional editing of the list
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
 // Return NO if you do not want the specified item to be editable.
 return YES;
}
*/


/*
 Override if you support rearranging the list
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/


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


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

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

- (void)viewWillDisappear:(BOOL)animated {
}

- (void)viewDidDisappear:(BOOL)animated {
}


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


- (void)didReceiveMemoryWarning {
 [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
 // Release anything that's not essential, such as cached data
}


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


- (UIButton *) getDetailDiscolosureIndicatorForIndexPath: (NSIndexPath *) indexPath  
{  
    UIButton *button = [UIButton buttonWithType: UIButtonTypeDetailDisclosure];  
    button.frame = CGRectMake(320.0 - 44.0, 0.0, 44.0, 44.0);  
    [button addTarget:self action:@selector(detailDiscolosureIndicatorSelected:) forControlEvents:UIControlEventTouchUpInside];  
    return button;
} 

- (void) detailDiscolosureIndicatorSelected: (UIButton *) sender  
{  
    //  
    // Obtain a reference to the selected cell  
    //  
    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath: [self.tableView indexPathForSelectedRow]];  

    //  
    // Do something like render a detailed view  
    //  
    /// ...
}

@end

- (void)applicationDidFinishLaunching:(UIApplication *)application {

 // Create the navigation and view controllers
 RootViewController *rootViewController = [[[RootViewController alloc] initWithStyle:UITableViewStylePlain] autorelease];

 UINavigationController *aNavigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
 self.navigationController = aNavigationController;

 NSArray * regioes = [self createRegions];
    rootViewController.regioesArray = regioes;


 [regioes release];
 [rootViewController release];
 [aNavigationController release];
 // Configure and show the window
 [window addSubview:[navigationController view]];
 [window makeKeyAndVisible];

}

错误出现在rootViewController.regioesArray = regioes; I can't ser any value o this property, not even "nil".

I can't ser any value o this property, not even "nil".


Here is the debug:

2010-10-16 01:35:43.965 TransitoRio[4224:207] *** -[RootViewController setRegioesArray:]: unrecognized selector sent to instance 0x1813ef0
2010-10-16 01:35:43.968 TransitoRio[4224:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[RootViewController setRegioesArray:]: unrecognized selector sent to instance 0x1813ef0'

Does anyone here knows what may be happening?

As asked, here is the "createRegions" method:

1 个答案:

答案 0 :(得分:1)

我看到您在头文件中声明您的数组是私有的,因此您不应该从类外部访问该属性。