0

古い iOS コードをいくつか継承し、それを新しい iOS 6 アプリケーションに統合しようとしました。ほとんどのコードを実装しましたが、これまでのところすべてが機能しています。私は今、その古いコードの最後の部分に取り組んでいます。アプリのニュース セクションの RSS を表示する一連のビューを実装しています。アイテムを選択すると、そのカテゴリ内の個々のアイテムが表示されるカテゴリ ビューを実装しました。ただし、何も表示されません。必要な変更をすべて行いましたが、iOS 開発の専門家ではないため、何らかのガイダンスが必要です。以下は、ビューを表示しようとしているシミュレーターのスナップショットです。その下は、私の .h および .m ファイルのコピーです。テーブル内の何かが表示されない原因がわかりません。

これがシミュレーターのスナップショットです

スナップショット

これは、テーブル ビューへのリンクを示すストーリーボードのスナップショットです。

スナップショット2

ここに.hファイルがあります

#import <UIKit/UIKit.h>
#import "BlogRssParser.h"

@class BlogRssParser;
@class BlogRssParserDelegate;
@class BlogRss;
@class XMLCategory;

@interface NewsViewController : UIViewController <UITableViewDataSource,UITableViewDelegate, BlogRssParserDelegate> {
    BlogRssParser * _rssParser;
    XMLCategory * _currItem;
}

@property (nonatomic, retain) BlogRssParser * rssParser;
@property (readwrite, retain) XMLCategory * currItem;

@property (nonatomic, retain) IBOutlet UITableView *itemTableView;

@end

ここに私の.mファイルがあります

#import "NewsViewController.h"
#import "NewsDetailsViewController.h"
#import "BlogRssParser.h"
#import "BlogRss.h"
#import "XMLCategory.h"

#define kLabelTag 1;

@interface NewsViewController ()

@end

@implementation NewsViewController

@synthesize rssParser = _rssParser;
@synthesize currItem = _currItem;

- (void)navBarInit {
    UIBarButtonItem *refreshBarButton = [[UIBarButtonItem alloc]
                                         initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
                                         target:self action:@selector(reloadRss)];

    [self.navigationItem setRightBarButtonItem:refreshBarButton animated:YES];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.itemTableView.delegate = self;
    self.itemTableView.dataSource = self;

- (void) viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self navBarInit];
    [self.itemTableView reloadData];
    self.itemTableView.userInteractionEnabled = NO;    
}

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    _rssParser = [[BlogRssParser alloc]init];
    _rssParser.delegate = self;

    [[self rssParser]startProcess:[_currItem categoryId]];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)reloadRss{
    [[self rssParser]startProcess:[_currItem categoryId]];
    [[self itemTableView]reloadData];
}

- (void)processCompleted{
    [[self itemTableView]reloadData];
//  _tableView.userInteractionEnabled = YES;
    [[self itemTableView]setUserInteractionEnabled:YES];
}

-(void)processHasErrors{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"My Title" message:@"Unable to retrieve the news. Please check if you are connected to the internet."
                                                   delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
    [alert show];
}

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

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

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

    const CGFloat LABEL_TITLE_HEIGHT = 70.0;
    const CGFloat LABEL_WIDTH = 210.0;

    NSString * mediaUrl = [[[[self rssParser]rssItems]objectAtIndex:indexPath.row]mediaUrl];
    NSData * imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:mediaUrl]];
    UIImage * imageFromImageData;
    if (imageData == nil) {
        imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:@"http://www.urlForImage.image.png"]];
    }
    imageFromImageData = [[UIImage alloc] initWithData:imageData];


    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"rssItemCell"];
    if(nil == cell){
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"rssItemCell"];

        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

        UILabel * _topLabel =
        [[UILabel alloc]
         initWithFrame:
         CGRectMake(
                    imageFromImageData.size.width + 10.0,
                    0.0,
                    LABEL_WIDTH,
                    LABEL_TITLE_HEIGHT)];


        _topLabel.tag = kLabelTag;
        _topLabel.opaque = NO;
        _topLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin;
        _topLabel.backgroundColor = [UIColor clearColor];
        _topLabel.textColor = [UIColor colorWithRed:0.25 green:0.0 blue:0.0 alpha:1.0];
        _topLabel.highlightedTextColor = [UIColor colorWithRed:1.0 green:1.0 blue:0.9 alpha:1.0];
        _topLabel.font = [UIFont systemFontOfSize:[UIFont labelFontSize]];
        _topLabel.numberOfLines = 0;
        [cell.contentView addSubview:_topLabel];
    }

    cell.imageView.image = imageFromImageData;

    UILabel * topLabel = (UILabel *)[cell.contentView viewWithTag:1];
    topLabel.text = [[[[self rssParser]rssItems]objectAtIndex:indexPath.row]title];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    NewsDetailsViewController *tlc = [[DetailsViewController alloc]init];
    tlc.currentItem = [[[self rssParser]rssItems]objectAtIndex:indexPath.row];
    tlc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

    [self presentViewController:tlc animated:YES completion:nil];
}

@end
4

3 に答える 3

4

あなたが直面している問題について結論を出すことができませんでした。

ただし、確認すべき点がいくつかあります。

あなたのスクリーンショットに空のテーブルビューさえ見えないので

  1. NibファイルにTableViewがありますか?
  2. Nib ファイルから IBOutlet itemTableView にマップされます。
于 2013-08-23T19:15:05.640 に答える
0

少なくとも 1 つのテーブル ビュー セルを追加します (1 つのプロトタイプ セルをドラッグ アンド ドロップします)。このように ここに画像の説明を入力 ここに画像の説明を入力

次に、そのセルを選択し、この識別子を使用して「再利用識別子」に名前を付けて、データソースを許可します..

于 2013-08-27T10:04:00.110 に答える