1

セルに関する情報を 1 行で追加できるようにするメソッドを customCell.m に追加したいので、以下を追加しました。

 -(void) addInfo:(NSString*) pTitre:(NSString*) pDescritption:(NSString*) pDate: (NSString*)pImage
{
    [[self titre] setText:pTitre];
    [[self description] setText:pDescritption];
    [[self date] setText:pDate];
    [[self couverture] setImage:[UIImage imageNamed:pImage]];
}

しかし、次のように mytableview.m でメソッドを呼び出すと:

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 3 ;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyIdentifier = @"firstviewcustomcellCell";

firstviewcustomcellCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];

if (cell == nil)
{
    NSArray *topLevelObject=[[NSBundle mainBundle] loadNibNamed:@"firestViewCell" owner:nil options:nil];

            for(id currentObject in topLevelObject)
            {
                if([currentObject isKindOfClass:[firstviewcustomcellCell class]])
                {
                    cell=(firstviewcustomcellCell*) currentObject;
                    break;
                }
            }    
}
    [cell addInfo:
     @"journal 1":
     @"description 1":
     @"01/02/2012":
        @"second.png"];

    [cell addInfo:
     @"journal 2":
     @"description 2":
     @"01/02/2012":
     @"second.png"];

    return cell;

}

これはそれが示すものです:

http://img213.imageshack.us/img213/2346/capturedcran20120416142.png

お時間をいただきありがとうございます

4

2 に答える 2

0
[cell addInfo:
 [NSString stringWithFormat:@"journal 1"]:
 [NSString stringWithFormat:@"description 1"]:
 [NSString stringWithFormat:@"01/02/2012"]:
    @"second.png"];

[cell addInfo:
 [NSString stringWithFormat:@"journal 2"]:
 [NSString stringWithFormat:@"description 2"]:
 [NSString stringWithFormat:@"01/02/2012"]:
 @"second.png"];

コードのこの部分を観察してください。そこには条件はありません。

代わりにこのようにします

[cell addInfo:
 [NSString stringWithFormat:@"journal %i", indexpath.row]:
 [NSString stringWithFormat:@"description %i", indexpath.row]:
 [NSString stringWithFormat:@"01/02/2012"]:
    @"second.png"];
于 2012-04-16T12:36:01.143 に答える
0

すべてのセル情報を一度に追加することはできません...一度に1つのセル情報を追加する必要があります...そして、すべてのセル情報を追加したい場合は、条件を入力するよりも一度に追加します..

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
 return 3 ;
}

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:   (NSIndexPath *)indexPath
 {
  static NSString *MyIdentifier = @"firstviewcustomcellCell";

   firstviewcustomcellCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];

   if (cell == nil)
 {    
  NSArray *topLevelObject=[[NSBundle mainBundle] loadNibNamed:@"firestViewCell" owner:nil options:nil];

        for(id currentObject in topLevelObject)
        {
            if([currentObject isKindOfClass:[firstviewcustomcellCell class]])
            {
                cell=(firstviewcustomcellCell*) currentObject;
                break;
            }
        }    
   }



if(indexPath.row == 1)
 {
  [cell addInfo:
 [NSString stringWithFormat:@"journal 1"]:
 [NSString stringWithFormat:@"description 1"]:
 [NSString stringWithFormat:@"01/02/2012"]:
    @"second.png"];
}
  else if(indexPath.row == 2)
 {

  [cell addInfo:
  [NSString stringWithFormat:@"journal 2"]:
 [NSString stringWithFormat:@"description 2"]:
 [NSString stringWithFormat:@"01/02/2012"]:
 @"second.png"];
 }

return cell;

 }

うまくいけば、それはあなたを助けるでしょう...チル

于 2012-04-16T12:40:52.223 に答える