1

コード全体は次のとおりです。

- (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
  1. このコードでは、objectForKey と valueForKey という 2 つの異なる形式を使用しているのはなぜですか?
  2. objectForKey で self.myManagedObject を呼び出す必要がないのはなぜですか?
  3. 説明の目的は何ですか?
4

2 に答える 2

2

このコードでは、objectForKey と valueForKey という 2 つの異なる形式を使用しているのはなぜですか?

objectForKey で self.myManagedObject を呼び出す必要がないのはなぜですか?

self.myManagedObjectですNSManagedObjectobjectForKey:の方法はありませんNSManagedObject

rowNSDictionaryタイプです。objectForKey:辞書方式です。

説明の目的は何ですか?

[self.myManagedObject valueForKey:[row objectForKey:@"key"]]NSStringとして型プロパティを含むオブジェクトを返す必要がありますdescription

それらは単一の行としてだけです。次のように複数の行に分割できます

YourCustomClass *customclassObj = [self.myManagedObject valueForKey:[row objectForKey:@"key"]];

cell.detailTextLabel.text = customclassObj.description;
于 2013-03-27T20:56:49.873 に答える
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;

}
于 2015-05-06T05:58:31.420 に答える