0
我在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;
}
我真的不知道到哪裏尋找錯誤。
非常感謝!
格蘭尼特
非常感謝你。你幫了我很多:) – Granit 2013-03-14 00:25:57