的UITableViewController无法识别的选择发送到实例0xa17c1f0
问题描述:
我在iOS开发是新的,目前我的工作。有4个选项卡的选项卡式应用程序。在我的一个选项卡上,我尝试显示一个表格视图,但出现以下错误。的UITableViewController无法识别的选择发送到实例0xa17c1f0
2013年3月13日14:15:35.416 STAM [4054:C07] - [的UITableViewController setProducts:]:无法识别的选择发送到实例0xa17c1f0
我创建了一个ProductsViewController类,这是的UITableViewController的子类,并且我把TableViewController连接到了StoryBoard中的ProductViewController。
我还创建了一个产品类,我插入以下属性:
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;
}
我真的不知道到哪里寻找错误。
非常感谢!
格兰尼特
答
行:
productsViewController.products = products;
转换为:
[productsViewController setProducts: products];
在您所提供的代码有没有一个“读写”的产品属性提也没有你提供了上面的方法。你可能会与正常做到这一点:
@interface ProductViewController ...
@property (readwrite) NSArray *products
// ...
@end
@implementation ProductViewController
@synthesize products
// ...
@end
非常感谢你。你帮了我很多:) – Granit 2013-03-14 00:25:57