1

Objective C でのプログラミングは初めてです

これが私のジレンマです: Web から JSON ファイルを取得していて、要素の 1 つ (currDate) を tableView に表示できますが、さらに多くの要素を表示したいと考えています。以下のコードから、currDate と prevDate の両方を表示します。

ここでロジックを変更する必要があります。

for (NSDictionary *diction in arrayOfEntry) {
    NSString *currDate = [diction objectForKey:@"Current Date"];
    a = currDate;
    NSString *prevDate = [diction objectForKey:@"Previous Date"];
    b = prevDate;     

    [array addObject:a]; 

    }
    [[self myTableView]reloadData];

ここで何かを変更する必要があるかどうかはわかりませんが、viewTable に配列を表示する方法を示すために添付しています。

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [array count];
}

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

if(!cell)
{
    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault     reuseIdentifier:CellIdentifier];
}

cell.textLabel.text = [array objectAtIndex:indexPath.row];
//cell.textLabel.text = [array objectsAtIndexes:indexPath.row];
return cell;
}
4

3 に答える 3

0

arrayOfEntryグローバルにする。.hファイル内

NSArray *arrayOfEntry;

numberOfRowsInSection

[arrayOfEntry count]

tableView: cellForRowAtIndexPath

NSString *currDate = [[arrayOfEntry objectAtIndex:indexPath.row] objectForKey:@"Current Date"]
NSString *prevDate = [[arrayOfEntry objectAtIndex:indexPath.row] objectForKey:@"Previous Date"]
cell.textLabel.text = [NSString stringWithFormat:@"%@   %@", currDate, prevDate];
于 2012-11-17T20:57:45.837 に答える
0

別の行を追加するだけです:

[array addObject:a];
[array addObject:b];
于 2012-11-17T21:00:48.153 に答える