我有一个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
答案 0 :(得分:0)
如果要在webview中显示内容,请尝试
webview.scalesPageToFit = YES;
一切顺利。