开发者

trying to display full text of rss feed in iphone app

开发者 https://www.devze.com 2023-03-05 04:15 出处:网络
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 displ

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? Ive been looking around in the code for a while now and i cant seem to figure it out. Any suggestions welcome?

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

    @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.scalesPageToFit = YES;

All the best.

0

精彩评论

暂无评论...
验证码 换一张
取 消