我正在使用主详细信息模板。
头文件 MasterViewController.h:
#import <UIKit/UIKit.h>
//(Imported both MasterViewController.h and DetailViewController.h in implementation file of MasterViewController.m)
@class DetailViewController;
@interface MasterViewController : UITableViewController
@property (strong, nonatomic) DetailViewController *detailViewController;
-(void)createFlowerData;
@end
实现文件HeaderViewController.m:
@interface MasterViewController () {
NSMutableArray *_objects;
NSArray *_flowerData;
NSArray *_flowerSections;
}
@end
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)];
self.navigationItem.rightBarButtonItem = addButton;
self.detailViewController = (DetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
//invoking the method I implemented to give data to flowerData array
[self createFlowerData];
}
-(void)createFlowerData{
NSMutableArray *redFlowers;
NSMutableArray *blueFlowers;
redFlowers = [[NSMutableArray alloc] init];
blueFlowers = [[NSMutableArray alloc] init];
//create the 2 sections for the flowerSections array
_flowerSections = @[@"Red Flowers", @"Blue Flowers"];
//add the objects to the mutable array
//red flowers
[redFlowers addObject:@{@"name":@"Poppy",@"picture":@"Poppy.png",@"url":@"http://en.wikiepdia.org/wiki/Poppy"}];
[redFlowers addObject:@{@"name":@"Tulip",@"picture":@"Tulip.png",@"url":@"http://en.wikipedia.org/wiki/Tulip"}];
[redFlowers addObject:@{@"name":@"Gerbera",@"picture":@"Gerbera.png",@"url":@"http://en.wikiepdia.org/wiki/Gerbera"}];
//blue flowers
[blueFlowers addObject:@{@"name":@"Phlox",@"picture":@"Phlox.png",@"url":@"http:en.wikipedia.org/wiki/Gerbera"}];
[blueFlowers addObject:@{@"name":@"Pin Cushion Flower",@"picture":@"Pincushion flower.png",@"url":@"http://en.wikipedia.org/wiki/Scabious"}];
[blueFlowers addObject:@{@"name":@"Iris",@"picture":@"Iris.png",@"url":@"http://en.wikipedia.org/wiki/Iris_(plant)"}];
_flowerData = @[redFlowers, blueFlowers];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [_flowerSections count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//find the number of row elements in a given section of the flower Data array
return [_flowerData[section] count];
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
//index 0 is the red flower
//index 1 is the blue flower
return _flowerSections[section];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"flowerCell"];
cell.textLabel.text = _flowerData[indexPath.section][indexPath.row][@"name"];
cell.detailTextLabel.text = _flowerData[indexPath.section][indexPath.row][@"url"];
cell.imageView.image = _flowerData[indexPath.section][indexPath.row][@"picture"];
return cell;
}
然后,当我在 ios 模拟器(iPad)上构建应用程序时,我得到以下信息:
2013-09-01 23:49:40.015 flowerDetail2[2394:c07] -[__NSCFConstantString _isResizable]: unrecognized selector sent to instance 0x6af4
2013-09-01 23:49:40.017 flowerDetail2[2394:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString _isResizable]: unrecognized selector sent to instance 0x6af4'
*** First throw call stack:
(0x1c95012 0x10d2e7e 0x1d204bd 0x1c84bbc 0x1c8494e 0x4ca7ab 0x121ae9 0x2c1f 0xd18fb 0xd19cf 0xba1bb 0xcab4b 0x672dd 0x10e66b0 0x2291fc0 0x228633c 0x2291eaf 0x1062bd 0x4eb56 0x4d66f 0x4d589 0x4c7e4 0x4c61e 0x4d3d9 0x502d2 0xfa99c 0x47574 0x4776f 0x47905 0x8dceab6 0x50917 0x1496c 0x1594b 0x26cb5 0x27beb 0x19698 0x1bf0df9 0x1bf0ad0 0x1c0abf5 0x1c0a962 0x1c3bbb6 0x1c3af44 0x1c3ae1b 0x1517a 0x16ffc 0x1bed 0x1b15)
libc++abi.dylib: terminate called throwing an exception
(lldb)
(请注意,我没有包括所有内容,仅包括我认为重要的部分)
这让我一整天都发疯了,我检查了很多次,重写了整个东西,结果还是一样,我什至无法让单元格显示。我用谷歌搜索,我发现类似的东西意味着我正在向一个不知道如何处理它的方法发送消息,但我确定它是正确的?有人可以帮我调试一下吗!