0

ここ数日、この問題を探していました。

私のファイル .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;
    }
4

2 に答える 2

2

どのように設定していますself.newsCountか?

配列を に入れていないかself.newsCount、(より可能性が高い)配列newsCountなしretainingで " " を設定しています。

を使用していARCますか? そうでない場合は、そうする必要があります。

于 2013-05-06T04:54:02.093 に答える