我是新來的xcode,我有這個問題的應用程序崩潰給我這個錯誤,當我嘗試挖掘細胞去DetailViewcontroller有錯誤:*由於未捕獲的異常'NSInvalidArgumentException'而終止應用程序,原因:' - [__ NSCFDictionary練習]:無法識別的選擇器發送到實例0x8ca15b0'。我不確定是什麼原因。我在這裏複製的代碼:終止應用程序由於未捕獲的異常'NSInvalidArgumentExceptioneason:' - [__ NSCFDictionary練習]:無法識別的選擇器
MAsterViewcontroller.h
#import <UIKit/UIKit.h>
@interface MasterViewController : UITableViewController{
NSMutableArray* routines_;
NSMutableArray *routineinfo_;
}
@property (nonatomic,retain)NSMutableArray* routines;
@property (nonatomic,retain)NSMutableArray* routineinfo;
@end
文件MasterViewController.m
#import "MasterViewController.h"
#import "ClassDetailViewController.h"
#import "ClassConstants.h"
@implementation MasterViewController
@synthesize routines=routines_,routineinfo=routineinfo_;
- (void)awakeFromNib
{
[super awakeFromNib];
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *path = [[NSBundle mainBundle] pathForResource:@"Mills" ofType:@"plist"];
routines_= [[NSMutableArray alloc] initWithContentsOfFile:path];
//Uncomment the following line to displa an Edit button in the navgation bar for this view controller.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
}
- (void)dealloc {
[routines_ release];
[routineinfo_ release];
[super dealloc];
}
- (void)insertNewObject:(id)sender
{
// if (!_objects) {
// _objects = [[NSMutableArray alloc] init];
// }
// [_objects insertObject:[NSDate date] atIndex:0];
// NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
// [self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
#pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
//Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [self.routines count];
}
//Configure appearence of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
//Configure the cell.
cell.textLabel.text = [[self.routines objectAtIndex:indexPath.row]
objectForKey:NAME_KEY];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showDetail"]) {
// Get the data given the selected row
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSInteger IndexSelected=[indexPath row];
//NSDictionary *routinedata = [self->routines_ objectAtIndex:[indexPath row]];
// Pass that data on to the DetailViewController
DetailViewController *detailVC = segue.destinationViewController;
NSString *[email protected]"";;
switch (IndexSelected)
{
case 0:
pathSelected = [[NSBundle mainBundle] pathForResource:@"Mills0" ofType:@"plist"];
break;
case 1:
pathSelected = [[NSBundle mainBundle] pathForResource:@"Mills1" ofType:@"plist"];
break;
case 2:
pathSelected = [[NSBundle mainBundle] pathForResource:@"Mills2" ofType:@"plist"];
break;
default:
break;
}
routineinfo_= [[NSMutableArray alloc] initWithContentsOfFile:pathSelected];
detailVC.routineinfo = self.routineinfo;
}
}
@end
#import <UIKit/UIKit.h>
@interface DetailViewController : UITableViewController{
@private
NSMutableArray *routineinfo_;
}
@property (nonatomic, retain) NSMutableArray *routineinfo;
@end
ClassDetailViewController.h
#import <UIKit/UIKit.h>
@interface DetailViewController : UITableViewController{
@private
NSMutableArray *routineinfo_;
}
@property (nonatomic, retain) NSMutableArray *routineinfo;
@end
ClassDetailViewController.m文件
的子類文件LesMillsCell.h
#import <UIKit/UIKit.h>
@interface LesMillsCell : UITableViewCell{
@private
// UITableViewCell *lesmillscell_;
UILabel *Exercise_;
UILabel *Title_;
UILabel *Artist_;
UILabel *Time_;
NSMutableArray *routineinfo_;
}
@property (nonatomic, retain) IBOutlet UILabel *Exercise;
@property (nonatomic, retain) IBOutlet UILabel *Title;
@property (nonatomic, retain) IBOutlet UILabel *Artist;
@property (nonatomic, retain) IBOutlet UILabel *Time;
@end
LesMillsCells.m
#import "LesMillsCell.h"
#import "ClassConstants.h"
#import "MillsDetailsConstant.h"
@implementation LesMillsCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
謝謝您的幫助!
你崩潰的LesMillsCell.Exercise.text = [[self.routineinfo objectAtIndex :indexPath.row] objectForKey:EXERCISE_KEY];這條線對嗎? – Tirth
你可以請張貼的是內幕routineInfo的NSDictionary? – Xeieshan