尝试在 iPhone 应用程序中显示 RSS feed 的全文

发布于 2024-11-06 12:57:05 字数 9893 浏览 0 评论 0原文

我的应用程序中有一个 RSS 提要,但它不显示每篇文章的所有文本。它只显示应在 uiwebview 中显示的文本的大约一半。有没有办法让它显示大量文本?我已经在代码中查看了一段时间,但我似乎无法弄清楚。有什么建议欢迎吗?
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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼泪也成诗 2024-11-13 12:57:05

如果您在 webview 中显示内容。那么请

webview.scalesPageToFit = YES;

尽力而为。

If you are displaying the content in webview.Then try

webview.scalesPageToFit = YES;

All the best.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文