2013-03-13 1 views
0

Я новичок в iOS Development, и в настоящее время я работаю над вкладкой, содержащей 4 вкладки. На одной из моих вкладок я пытаюсь отобразить представление таблицы, но я получаю следующую ошибку.Непризнанный селектор UITableViewController отправлен в экземпляр 0xa17c1f0

2013-03-13 14: 15: 35,416 STAM [4054: C07] - [UITableViewController setProducts]: непризнанные селектор направлен например 0xa17c1f0

я создал класс ProductsViewController, который представляет собой подкласс UITableViewController , а также я подключил TableViewController к ProductViewController в StoryBoard.

Я также создал класс продукта, где я вставленный следующие свойства:

Product.h

#import <Foundation/Foundation.h> 

@interface Product : NSObject 
@property (nonatomic, copy) NSString *name; 
@property (nonatomic, copy) NSString *number; 
@end 

В AppDelegate.mi сделал следующее:

@implementation AppDelegate { 
NSMutableArray *products; 
} 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    products = [NSMutableArray arrayWithCapacity:20]; 

Product *product = [[Product alloc] init]; 
product.name = @"Test Product"; 
product.number = @"123546"; 
[products addObject:product]; 

product = [[Product alloc] init]; 
product.name = @"Test Product 2"; 
product.number = @"654321"; 
[products addObject:product]; 

UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController; 
UINavigationController *navigationController = [[tabBarController viewControllers] objectAtIndex:0]; 
ProductsViewController *productsViewController = [[navigationController viewControllers] objectAtIndex:0]; 
productsViewController.products = products; 

return YES; 
} 

И, наконец, в ProductViewController.h:

#pragma mark - Table view data source 

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

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

    return [self.products count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath  *)indexPath 
{ 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ProductCell"]; 
Product *product = [self.products objectAtIndex:indexPath.row]; 
cell.textLabel.text = product.name; 
    cell.detailTextLabel.text = product.number; 

    return cell; 
} 

Я действительно не знаю, где искать ошибку.

спасибо!

Granit

ответ

1

Линия:

productsViewController.products = products; 

Преобразуется:

[productsViewController setProducts: products]; 

В коде вы предоставили нет никакого упоминания о 'чтения-записи' продукты собственности и не имеют вы предоставили вышеуказанный метод. Обычно вы можете:

@interface ProductViewController ... 
@property (readwrite) NSArray *products 
// ... 
@end 


@implementation ProductViewController 
@synthesize products 
// ... 
@end 
+0

Большое спасибо. Вы мне очень помогли :) – Granit

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

  • Нет связанных вопросов^_^