UITableViewCell TitleLabel - 无法识别的选择器错误

时间:2014-12-20 13:22:57

标签: ios objective-c uitableview

我正在为我的应用程序设置一个简单的tableview,但似乎代码在XCode 6中不起作用,它在XCode 5中工作。我在启动屏幕加载后得到SIGABRT错误:

  

2014-12-19 13:44:06.584 TableTest Table [763:165564] - [UITableViewCell TitleLabel]:无法识别的选择器发送到实例0x14555e30   2014-12-19 13:44:06.586 TableTest表[763:165564] *由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:' - [UITableViewCell TitleLabel]:无法识别的选择器发送到实例0x14555e30'   * 第一次抛出调用堆栈:   (0x21a4f49f 0x2f205c8b 0x21a548b9 0x21a527d7 0x21984058 0x4b7c3 0x251d7787 0x251d784b 0x251ccfa1 0x24fe50df 0x24f0f24f 0x24937a0d 0x249333e5 0x2493326d 0x24932c51 0x24932a55 0x25173055 0x25173dfd 0x2517e209 0x25172217 0x281e00d1 0x21a15d7d 0x21a15041 0x21a13b7b 0x219613c1 0x219611d3 0x24f761bf 0x24f70fa1 0x4bbd1 0x2f785aaf)   libc ++ abi.dylib:以NSException类型的未捕获异常终止

我正在关注GeekyLemon的教程:https://www.youtube.com/watch?v=ITUI7fukRO8以下是使用的代码:

我已在此处粘贴代码,但代码也可在此链接中找到:http://www.geekylemon.com/xcode-tutorial-table-view-p1

谢谢!

TableViewController.h:

@interface TableViewController : UITableViewController {
}
@property (nonatomic, strong) NSArray *Images;
@property (nonatomic, strong) NSArray *Title;
@property (nonatomic, strong) NSArray *Description;
@end

TableViewController.m     @implementation ViewController

- (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;

        _Title = @[@"Big Ben",
                        @"Colosseum",
                        @"Great Wall of China",
                        @"St Basil’s Cathedral",
                        @"Statue of Liberty",
                        @"Stonehenge",
                        @"Taj Mahal",
                        @"The Eiffel Tower",
                        @"Tower of Pisa",];

        _Description = @[@"London, England",
                                  @"Rome, Italy",
                                  @"China",
                                  @"Moscow, Russia",
                                  @"Liberty Island, New York",
                                  @"Wiltshire, England",
                                  @"Agra, India",
                                  @"Paris, France",
                                  @"Pisa, Italy",];

    _Images = @[@"BigBen.jpg",
                        @"Colosseum.jpg",
                        @"GreatWallOfChina.jpeg",
                        @"StBasils.jpg",
                        @"StatueOfLiberty.jpg",
                        @"Stonehenge.jpg",
                        @"TajMahal.jpg",
                        @"EiffelTower.jpg",
                        @"TowerOfPisa.jpg",];
}

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

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{ 
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return _Title.count;
} 

@end

TableCell.h

@interface TableCell : UITableViewCell {
}
@property (strong, nonatomic) IBOutlet UILabel *TitleLabel;
@property (strong, nonatomic) IBOutlet UILabel *DescriptionLabel;
@property (strong, nonatomic) IBOutlet UIImageView *ThumbImage;
@end

再次使用TableViewController.m

#import "TableCell.h"

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"TableCell";
    TableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier           forIndexPath:indexPath];

    // Configure the cell...
    int row = [indexPath row]; 

    cell.TitleLabel.text = _Title[row];
    cell.DescriptionLabel.text = _Description[row];
    cell.ThumbImage.image = [UIImage imageNamed:_Images[row]];;

return cell;
}

2 个答案:

答案 0 :(得分:1)

有什么问题:您使用TableCell

的名称为dequeueReusableCellWithIdentifier课程使用相同的名称

使其有效......:

1)在你的故事板中点击你的手机并更改标识符..让我们说TableCell_identifier

2)在您的代码中相应更改static NSString *CellIdentifier = @"TableCell_identifier";

答案 1 :(得分:0)

看起来您的代码看起来不错。你会缺少的是:

TableViewController.h:
1. @interface RootViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource> 
2. At below line:
    static NSString *CellIdentifier = @"TableCell";
    It should be either static NSString *CellIdentifier = @"cell";
    or in your custom cell in storyboard/XIB, set TableViewCell identifier to "TableCell" as given in below image.

enter image description here