简体   繁体   English

试图在iPhone应用程序中显示RSS提要的全文

[英]trying to display full text of rss feed in iphone app

I have an rss feed working in my app but it doesnt display all the text of each article.It only displays about half of the text that it should display in the uiwebview.Is there anyway to make it display the lot of the text? 我的应用程序中有一个rss feed,但它不显示每篇文章的所有文本,仅显示应在uiwebview中显示的文本的一半,是否可以使它显示很多文本? Ive been looking around in the code for a while now and i cant seem to figure it out. 我已经在代码中四处寻找了一段时间,我似乎无法弄清楚。 Any suggestions welcome? 有什么建议吗?
TABLEVIEW.H TABLEVIEW.H

    @class NewsreelViewController;

    @interface ClubNewsTableView : UITableViewController {UITableViewDelegate,        UITableViewDataSource} {  
       UIActivityIndicatorView *activityIndicator;    
    NSArray *items;  
    IBOutlet UITableView *clubNewsTableView;  
    NSMutableArray *clubNewsArray;  
    NewsreelViewController *newsreelViewController;  
    }  
    @property (nonatomic, retain) NSMutableArray *clubNewsArray;  
    @property (nonatomic, retain) NewsreelViewController *newsreelViewController;  
    @property (retain, nonatomic) UIActivityIndicatorView *activityIndicator;    
    @property (retain, nonatomic) NSArray *items;    
    @end  

TABLEVIEW.M TABLEVIEW.M

    @interface ClubNewsTableView (PrivateMethods)    
    - (void)loadData;    
    @end     


    @implementation ClubNewsTableView  
    @synthesize clubNewsArray;  
    @synthesize newsreelViewController;  
    @synthesize activityIndicator, items;  

    - (id)initWithStyle:(UITableViewStyle)style  
    {  
    self = [super initWithStyle:style];  
    if (self) {  
    // Custom initialization  

    }  
     return self;    
    }  

    - (void)dealloc  
    {  
    [activityIndicator release];    
    [items release];  
    [clubNewsArray release];  
    [super dealloc];  
    }  

    - (void)didReceiveMemoryWarning  
    {  
    // Releases the view if it doesn't have a superview.  
    [super didReceiveMemoryWarning];  

    // Release any cached data, images, etc that aren't in use.  
     }  


    - (void)viewDidLoad  
    {  
        [super viewDidLoad];  

        // Uncomment the following line to preserve selection between presentations.  
        // self.clearsSelectionOnViewWillAppear = NO;  

        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.  
        // self.navigationItem.rightBarButtonItem = self.editButtonItem;  
        UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc]  initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];    
       indicator.hidesWhenStopped = YES;    
        [indicator stopAnimating];    
        self.activityIndicator = indicator;    
        [indicator release];    

        UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithCustomView:indicator];    
        self.navigationItem.rightBarButtonItem = rightButton;    
        [rightButton release];    
    }  

    - (void)viewDidUnload  
    {  
        [super viewDidUnload];  
        self.clubNewsArray = nil;  
        // Release any retained subviews of the main view.  
        // e.g. self.myOutlet = nil;  
    }  

    - (void)viewWillAppear:(BOOL)animated  
    {  
        [super viewWillAppear:animated];  
    }  

    - (void)viewDidAppear:(BOOL)animated  
    {  
        [self loadData];  
        [super viewDidAppear:animated];  
    }  

    - (void)loadData {    
        if (items == nil) {    
            [activityIndicator startAnimating];    

            Parser *rssParser = [[Parser alloc] init];    
            [rssParser parseRssFeed:@"http://www.clontarfrugby.com/feed/" withDelegate:self];    

            [rssParser release];    

        } else {    
            [self.tableView reloadData];    
        }    

    }    

    - (void)receivedItems:(NSArray *)theItems {    
        items = theItems;    
        [self.tableView reloadData];    
        [activityIndicator stopAnimating];    
    }    

    - (void)viewWillDisappear:(BOOL)animated  
    {  
        [super viewWillDisappear:animated];  
    }  

    - (void)viewDidDisappear:(BOOL)animated  
    {  
        [super viewDidDisappear:animated];  
    }  

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation  
    {  
        // Return YES for supported orientations  
        return (interfaceOrientation == UIInterfaceOrientationPortrait);  
    }  

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView  
    {  
    //#warning Potentially incomplete method implementation.  
        // Return the number of sections.  
        return 1;  
    }  

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section  
    {  
    //#warning Incomplete method implementation.  
        // Return the number of rows in the section.  
        return [items count];  
    }  

    - (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 = [[items objectAtIndex:indexPath.row] objectForKey:@"title"];    
        cell.detailTextLabel.text = [[items objectAtIndex:indexPath.row] objectForKey:@"date"];    

        NSString *imageName = [[items objectAtIndex:indexPath.row] objectForKey:@"image"];  
        UIImageView *titleImage = (UIImageView *)[cell viewWithTag:2];  
        UIImage *image = [UIImage imageNamed:imageName];    
        [titleImage setImage:image];  


        // Format date    
        NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];      
        [dateFormatter setDateStyle:NSDateFormatterMediumStyle];    
        [dateFormatter setTimeStyle:NSDateFormatterNoStyle];    
        //cell.detailTextLabel.text = [[[[self rssParser]rssItems]objectAtIndex:indexPath.row]description];  
        //cell.detailTextLabel.text = [[items objectAtIndex:indexPath.row]   objectForKey:@"date"];    
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;    
        return cell;    
    }  

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath         *)indexPath  
    {  
        // Navigation logic may go here. Create and push another view controller.  
        /*
         <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
         // ...
         // Pass the selected object to the new view controller.
         [self.navigationController pushViewController:detailViewController animated:YES];
         [detailViewController release];
         */

        NSDictionary *theItem = [items objectAtIndex:indexPath.row];    
        NewsreelViewController *nextController = [[NewsreelViewController alloc] initWithNibName:@"NewsreelViewController" bundle:nil];  
        nextController.item=theItem;    
        [self.navigationController pushViewController:nextController animated:YES];    
        [nextController release];   

    }  

    @end  

DETAILVIEW.H 详细资料

     #import <UIKit/UIKit.h>


    @interface NewsreelViewController : UIViewController {
NSDictionary *item;  
IBOutlet UILabel *itemTitle;  
IBOutlet UILabel *itemDate;  
IBOutlet UIWebView *itemSummary; 
IBOutlet UIWebView *itemImage;
     }  

    @property (retain, nonatomic) NSDictionary *item;  
    @property (retain, nonatomic) IBOutlet UILabel *itemTitle;  
    @property (retain, nonatomic) IBOutlet UILabel *itemDate;  
    @property (retain, nonatomic) IBOutlet UIWebView *itemSummary; 
    @property (retain, nonatomic) IBOutlet UIWebView *itemImage;

    - (id)initWithItem:(NSDictionary *)theItem;  

    @end

DETAILVIEW.M 详细资料

    @implementation NewsreelViewController
    @synthesize item, itemTitle, itemDate, itemSummary, itemImage;
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
            // Custom initialization
        }
        return self;
    }

    - (void)dealloc
    {
        [item release];  
        [itemTitle release];  
        [itemDate release];  
        [itemSummary release];  
        [itemImage release];
        [super dealloc];
    }

    - (void)didReceiveMemoryWarning
    {
        // Releases the view if it doesn't have a superview.
        [super didReceiveMemoryWarning];

        // Release any cached data, images, etc that aren't in use.
    }

    #pragma mark - View lifecycle

    - (id)initWithItem:(NSDictionary *)theItem {  
        if (self = [super initWithNibName:@"Detail" bundle:nil]) {  
            self.item = theItem;  
            self.title = [item objectForKey:@"title"];  
        }  

        return self;  
    }   

    - (void)viewDidLoad {  
        [super viewDidLoad];  

        self.itemTitle.text = [item objectForKey:@"title"];  

        NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];    
        [dateFormatter setDateStyle:NSDateFormatterMediumStyle];  
        [dateFormatter setTimeStyle:NSDateFormatterNoStyle];  

        self.itemDate.text = [item objectForKey:@"date"];  
        [self.itemImage loadHTMLString:[item objectForKey:@"image"] baseURL:nil];
        [self.itemSummary loadHTMLString:[item objectForKey:@"summary"] baseURL:nil];  
    }

    - (void)viewDidUnload
    {
        [super viewDidUnload];
        // Release any retained subviews of the main view.
        // e.g. self.myOutlet = nil;
    }

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        // Return YES for supported orientations
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }
    @end

If you are displaying the content in webview.Then try 如果要在Webview中显示内容,请尝试

webview.scalesPageToFit = YES;

All the best. 祝一切顺利。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM