2011-06-30 14 views
0

xmlから値を取得しています。私が取り組んでいるのはうまくいきますが、セルに値を表示する際に問題に直面します。私は最初のセルと2番目のセル4の値に6つの値を表示する必要がありますどのように私はこれを行うことができますか?最初のセルでは、次のセルで同じ値が繰り返されるためです。iPhoneのセルにxml値を表示する方法

これは私のセルのコードです:

#import <UIKit/UIKit.h> 
#import "TWeatherParser.h" 
@class TWeatherParser; 


@interface TWeatherController : UITableViewController { 

    UITableView *mTableView; 
    NSMutableArray *mImage; 
    NSMutableArray *weatherarray; 
    TWeatherParser *weather; 
} 
@property (nonatomic, retain) IBOutlet UITableView *mTableView; 
@property (nonatomic, retain) NSMutableArray *weatherarray; 
@property (nonatomic, retain) TWeatherParser *weather; 

@end 





    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

     static NSString *CellIdentifier = @"Cell"; 


     TWeatherCell *cell =(TWeatherCell *) [mTableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if (cell == nil) { 
      cell = [[[TWeatherCell alloc] initWithStyle:UITableViewStyleGrouped reuseIdentifier:CellIdentifier] autorelease]; 
     } 
     TWeatherElement *newobj = [weatherarray objectAtIndex:indexPath.row]; 
     if ([newobj.icon isEqualToString:@"http://\n"]) 
     { 
      cell.weatherimage.image = [UIImage imageNamed:@"listIcon-H.png"]; 
     } 
     else { 
      NSData *imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:newobj.icon]]; 
      cell.weatherimage.image = [UIImage imageWithData:imageData]; 
      [imageData release]; 
     } 
     cell.reportdate.text = newobj.currentdate; 
     NSLog(@"this is cell1 value:%@",cell.reportdate.text); 
     cell.conditionname.text = newobj.conditionname; 
     NSLog(@"this is cell2 value:%@",cell.conditionname.text); 
     cell.twotemp.text = [NSString stringWithFormat:@"Temp:%@/%@",newobj.mintemp,newobj.maxtemp]; 
     NSLog(@"this is cell3 value:%@",cell.twotemp.text); 
     cell.twodirection.text = newobj.wind; 
     NSLog(@"this is cell4 value:%@",cell.twodirection.text); 
     cell.humidity.text = newobj.humidity; 
     NSLog(@"this is cell5 value:%@",cell.humidity.text); 
     //cell.reportdate.text = newobj.currentdate; 


     //cell.reportdate.text [email protected]"My journey"; 
    // cell.conditionname.text = @"raji"; 
    // cell.twotemp.text = @"pradeep"; 
    // cell.twodirection.text = @"harish"; 
    // cell.humidity.text [email protected]"23"; 
    // cell.weatherimage.image = [UIImage imageNamed:@"listIcon-H.png"]; 
     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

     // Configure the cell... 

     return cell; 
    } 

答えて

1

を変更します

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

ListDetailCell *cell= [[[ListDetailCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 

tableView.backgroundColor = [UIColor whiteColor]; 

if (cell == nil) 
{ 
    cell = [[[ListDetailCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] 
      autorelease]; 
} 

switch (indexPath.row) 
{ 
    case 0: 
     NSLog(@"%d",indexPath.row); 
     cell.leadingLabel.text = @"Name: "; 
     cell.leadingLabel.font = [UIFont fontWithName:LABELS_FONT_NAME_BOLD size:11.0f]; 
     cell.leadingLabel.textColor = FONT_GREEN_COLOR; 

     cell.volInfo.text = volRow.volName; 
     cell.volInfo.font = [UIFont fontWithName:LABELS_FONT_NAME size:11.0f]; 
     break; 
    case 1: 
     NSLog(@"%d",indexPath.row); 
     cell.leadingLabel.text = @"Address: "; 
     cell.leadingLabel.font = [UIFont fontWithName:LABELS_FONT_NAME_BOLD size:11.0f]; 
     cell.leadingLabel.textColor = FONT_GREEN_COLOR; 

     cell.volInfo.text = volRow.volAddress; 
     cell.volInfo.font = [UIFont fontWithName:LABELS_FONT_NAME size:11.0f]; 
     break; 
    case 2: 
     NSLog(@"%d",indexPath.row); 
     cell.leadingLabel.text = @"Phone: "; 
     cell.leadingLabel.font = [UIFont fontWithName:LABELS_FONT_NAME_BOLD size:11.0f]; 
     cell.leadingLabel.textColor = FONT_GREEN_COLOR; 

     cell.volInfo.text = volRow.phone; 
     cell.volInfo.font = [UIFont fontWithName:LABELS_FONT_NAME size:11.0f]; 
     break; 
    case 3: 
     NSLog(@"%d",indexPath.row); 
     cell.leadingLabel.text = @"Email: "; 
     cell.leadingLabel.font = [UIFont fontWithName:LABELS_FONT_NAME_BOLD size:11.0f]; 
     cell.leadingLabel.textColor = FONT_GREEN_COLOR; 

     cell.volInfo.text = volRow.email; 
     cell.volInfo.font = [UIFont fontWithName:LABELS_FONT_NAME size:11.0f]; 
     break; 

    default: 
     NSLog(@"Out of Range ",indexPath.row); 
     break; 
} 

return cell; 
} 
+0

@maulikは動作しません – Rocky

+0

エラーが発生しましたか? – Maulik

+0

私は別のセルでforcastの日を呼び出すことを知っていることを知りたいです – Rocky

0

使用NSXMLParser、その後キーで値をフェッチし、作り、あなたの配列の辞書と店を作るxmlファイルを解析します。

cellForRowAtIndexPathのコードは、データを表示するのに十分です。しかし、あなたは別のセルで異なる値を表示したい場合、あなたは行インデックスを検出するスイッチケースを使用する必要があります...それに応じ

+0

私はこの事をすべて私はcreatパーサークラスを行ったが、私の問題は異なる値を表示する方法です。異なるセル – Rocky

+0

あなたはそれぞれのセルごとに異なるオブジェクトにアクセスしています。 – Ishu

0

あなたは一意の識別子で、各セルを特定する必要があります以下のような文字列 -

UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:[NSString stringWithFormat:@"cell_%d", indexPath.row]]; 

if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:[NSString stringWithFormat:@"cell_%d", indexPath.row]] autorelease]; 
} 

これにより、あなたはどちらかの前に6つの項目または4つの項目で作成した同じセル(1回目)再利用のtableViewができるようになります。

関連する問題