ここ数日、この問題を探していました。
私のファイル .h で、これをインターフェースに入れました:
NSMutableArray *newsCount;
@property (nonatomic, retain) NSMutableArray *newsCount;
そして、ファイル .m にこのコードを書きました。
これをビューのWill Appearメソッドに割り当てました:
- (void)viewWillAppear:(BOOL)animated{
self.newsCount = [[NSMutableArray alloc] init];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.newsCount count];
// return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
cell.textLabel.text = [NSString stringWithFormat:@"- %@",[[newsCount objectAtIndex: indexPath.row] objectForKey:@"RELATED_CAPTION"]];
[cell.textLabel setFont:[UIFont fontWithName:@"Helvetica" size:13]];
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.numberOfLines = 2;
cell.textLabel.textColor = [UIColor grayColor];
return cell;
}