iOS/iPhone Table View and Table View Cell - Custom Cell Column ทำตามแล้ว errorครับ
Error นี้ไม่รู้แก้ที่ไหนครับ ผมทำตามตัวอย่างแล้วครับ
พอผมลบ displayCreateDate มันก็ขึ้น displayDescriptionครับ
2015-01-23 11:04:16.366 Test4[2663:56453] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<ViewController 0x7fb94144f330> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key displayCreateDate.'
ViewController.m
#import "ViewController.h"
#import "CustomTableCell.h"
@interface ViewController ()
{
NSMutableArray *myObject;
// A dictionary object
NSDictionary *dict;
// Define keys
NSString *images;
NSString *name;
NSString *description;
NSString *createdate;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// Define keys
images = @"Images";
name = @"Name";
description = @"Description";
createdate = @"CreateDate";
// Create array to hold dictionaries
myObject = [[NSMutableArray alloc] init];
dict = [NSDictionary dictionaryWithObjectsAndKeys:
@"1.jpg", images,
@"Girl 1", name,
@"Girl 1 Description", description,
@"01-Nov-2012 12:00", createdate,
nil];
[myObject addObject:dict];
dict = [NSDictionary dictionaryWithObjectsAndKeys:
@"2.jpg", images,
@"Girl 2", name,
@"Girl 2 Description", description,
@"01-Nov-2012 13:00", createdate,
nil];
[myObject addObject:dict];
dict = [NSDictionary dictionaryWithObjectsAndKeys:
@"3.jpg", images,
@"Girl 3", name,
@"Girl 3 Description", description,
@"01-Nov-2012 14:00", createdate,
nil];
[myObject addObject:dict];
dict = [NSDictionary dictionaryWithObjectsAndKeys:
@"4.jpg", images,
@"Girl 4", name,
@"Girl 4 Description", description,
@"01-Nov-2012 15:00", createdate,
nil];
[myObject addObject:dict];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return myObject.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
CustomTableCell *cell = (CustomTableCell *) [tableView dequeueReusableCellWithIdentifier : CellIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomTableCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
NSDictionary *tmpDict = [myObject objectAtIndex:indexPath.row];
UIImage* theImage = [UIImage imageNamed:[tmpDict objectForKey:images]];
cell.displayImage.image = theImage;
cell.displayName.text = [tmpDict objectForKey:name];
cell.displayDescription.text = [tmpDict objectForKey:description];
cell.displayCreateDate.text = [tmpDict objectForKey:createdate];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 100;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc {
[_myTable release];
[super dealloc];
}
@end
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (retain, nonatomic) IBOutlet UITableView *myTable;
@end
CustomTableCell.h
#import <UIKit/UIKit.h>
@interface CustomTableCell : UITableViewCell
@property (nonatomic, strong) IBOutlet UIImageView *displayImage;
@property (nonatomic, strong) IBOutlet UILabel *displayName;
@property (nonatomic, strong) IBOutlet UILabel *displayDescription;
@property (nonatomic, strong) IBOutlet UILabel *displayCreateDate;
@end
CustomTableCell.m
#import "CustomTableCell.h"
@implementation CustomTableCell
@synthesize displayImage = _displayImage;
@synthesize displayName = _displayName;
@synthesize displayDescription = _displayDescription;
@synthesize displayCreateDate = _displayCreateDate;
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
Tag : Mobile
Date :
2015-01-23 11:16:14
By :
crisisbank
View :
935
Reply :
3
อันนี้เป็นหน้าเชื่อมครับ
Date :
2015-01-23 11:56:56
By :
crisisbank
ผมว่าในบทความก็ละเอียดแล้วน่ะครับ
Date :
2015-01-25 14:50:57
By :
mr.win
Load balance : Server 00