以下是整个代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"DetailCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2
reuseIdentifier:CellIdentifier];
NSUInteger sectionIndex = [indexPath section];
NSUInteger rowIndex = [indexPath row];
NSDictionary *section = [self.sections objectAtIndex:sectionIndex];
NSArray *rows = [section objectForKey:@"rows"];
NSDictionary *row = [rows objectAtIndex:rowIndex];
cell.textLabel.text = [row objectForKey:@"label"];
cell.detailTextLabel.text = [[self.myManagedObject valueForKey:[row objectForKey:@"key"]] description];
return cell;
}
我的问题是:
cell.textLabel.text = [row objectForKey:@"label"];
cell.detailTextLabel.text = [[self.myManagedObject valueForKey:[row objectForKey:@"key"]] description]; //This is NSDate
答案 0 :(得分:2)
为什么这段代码使用两种不同的格式:objectForKey& valueForKey?
为什么不需要调用self.myManagedObject objectForKey?
self.myManagedObject
是NSManagedObject
。 objectForKey:
没有NSManagedObject
方法。
row
是NSDictionary
类型。 objectForKey:
是一种字典方法。
描述的目的是什么?
[self.myManagedObject valueForKey:[row objectForKey:@"key"]]
应该返回一个包含NSString
类型属性description
的对象。
它们只是一条线。您可以按如下方式将其拆分为多行
YourCustomClass *customclassObj = [self.myManagedObject valueForKey:[row objectForKey:@"key"]];
cell.detailTextLabel.text = customclassObj.description;
答案 1 :(得分:0)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
//create new cell
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
[tableView setRowHeight: 50.00];
UILabel *name=[[UILabel alloc]initWithFrame:CGRectMake(10, 5, 70, 30)];
name.text=@"Ajay";
[cell.contentView addSubview:name];
[name release];
// cell.selectionStyle = UITableViewCellSelectionStyleNone;
//cell.contentView.backgroundColor=[UIColor whiteColor];
UIButton *btn1=[[UIButton alloc]initWithFrame:CGRectMake(80, 5, 70, 30)];
//UIButton *btn1=[UIButton buttonWithType:UIButtonTypeRoundedRect];
//btn1.frame=CGRectMake(80, 5, 40, 30);
[btn1 setTitle:@"Name" forState:UIControlStateNormal];
[btn1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//[btn1 addTarget:self action:@selector(Nam:) forControlEvents:UIControlEventTouchUpInside];
btn1.backgroundColor=[UIColor greenColor];
[[btn1 layer]setCornerRadius:8.0f];
[[btn1 layer]setBorderWidth:1.0f];
[cell.contentView addSubview:btn1];
[btn1 release];
UILabel *add=[[UILabel alloc]initWithFrame:CGRectMake(10, 56, 70, 50)];
add.text=@"Biliya";
[cell.contentView addSubview:add];
[add release];
// cell.selectionStyle = UITableViewCellSelectionStyleNone;
//cell.contentView.backgroundColor=[UIColor whiteColor];
UIButton *btn2=[[UIButton alloc]initWithFrame:CGRectMake(80, 56, 70, 30)];
//UIButton *btn1=[UIButton buttonWithType:UIButtonTypeRoundedRect];
//btn1.frame=CGRectMake(80, 5, 40, 30);
[btn2 setTitle:@"Address" forState:UIControlStateNormal];
[btn2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//[btn1 addTarget:self action:@selector(Nam:) forControlEvents:UIControlEventTouchUpInside];
btn2.backgroundColor=[UIColor greenColor];
[[btn2 layer]setCornerRadius:8.0f];
[[btn2 layer]setBorderWidth:1.0f];
[cell.contentView addSubview:btn2];
[btn2 release];
return cell;
}