2013-08-23 111 views
0

我已经继承了一些旧的iOS代码,并试图将其集成到新的iOS 6应用程序中。我已经实现了大部分代码,到目前为止一切工作都已经完成。我现在正在研究旧代码的最后一部分。我正在执行一组视图来显示我的应用的新闻部分的rss。我已经实现了类别视图,在选择一个项目后,它将显示该类别中的各个项目。但是没有显示。我已经做了所有我需要做的修改,但是我不是iOS开发专家,需要一些指导。下面是模拟器试图显示视图的快照,下面是我的.h和.m文件的副本。我不知道是什么阻止了桌子上的任何东西出现。并抢先感谢任何帮助!iOS UITableView未显示

这里的模拟器

snapshot

这里的快照故事板的显示链接到表视图

snapshot2

这里的快照是.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

我无法得出关于您面临的问题的结论。

但这里有几件事你应该检查。

因为我无法看到你的截图,甚至一个空表视图

  1. 你有没有上的TableView笔尖文件?
  2. 它从The Nib文件映射到IBOutlet itemTableView?
+1

我打算添加相同的注释,请确保在viewDidLoad中self.itemTableView不为零。如果是这样,你没有在界面构建器中链接它。 –

+0

我正在使用故事板,但它已链接。我必须仔细检查才能确定。并加倍确信我将取消链接并重新链接。感谢您的建议,我会让你知道我找到了什么。 – shadonar

+0

我已经双重检查,表视图是在故事板视图控制器上,并映射到IBOutlet itemTableView,但是从@KendallHelmstetterGelner关于检查self.itemTableView的评论,以及它是零。我添加了故事板项目,显示表格视图已链接。我究竟做错了什么? – shadonar

0

我会做的第一件事是确保[[[self rssParser] rssItems] count]真的返回> 0。此外,这是你的.m文件的副本&粘贴? viewDidLoad缺少结束大括号,但Xcode会捕获该结果。

0

添加至少一个表视图细胞(拖放一个原型细胞).. 这样 enter image description hereenter image description here

然后选择小区和“重用标识符”与该标识符给一些名称允许数据源。