ios 简单的rss 解析应用demo
来源:互联网 发布:乐乎车载净化器 编辑:程序博客网 时间:2024/05/16 04:45
1.主文件: RootViewController.h
#import <UIKit/UIKit.h>@interface RootViewController : UITableViewController {NSMutableArray *rssList;NSMutableDictionary *currentItem;NSMutableString *currentContents; }@property (nonatomic, retain) NSMutableArray *rssList;@end
#import "RootViewController.h"#import "InternetNewsAppDelegate.h"#import "DetailViewController.h"@implementation RootViewController@synthesize rssList;#pragma mark -#pragma mark View lifecycle- (void)viewDidLoad { [super viewDidLoad]; // Uncomment the following line to display an Edit button in the navigation bar for this view controller. // self.navigationItem.rightBarButtonItem = self.editButtonItem;self.title = @"国际要闻";self.rssList = [[NSMutableArray alloc] init];//NSXMLParser *firstParser = [[NSXMLParser alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://rss.sina.com.cn/news/world/focus15.xml"]]; NSXMLParser *firstParser = [[NSXMLParser alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.alibuybuy.com/feed"]];firstParser.delegate = self; [firstParser parse];}#pragma mark -#pragma mark NSXMLParser delegate Methods- (void)parserDidStartDocument:(NSXMLParser *)parser{NSLog(@"startParser----------------------");}- (void)parserDidEndDocument:(NSXMLParser *)parser{NSLog(@"end:----------------------");[parser release];NSLog(@"%@",rssList);}- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{if([elementName isEqualToString:@"item"]){currentItem = [[NSMutableDictionary alloc] init];}else if (currentItem != NULL){currentContents = [[NSMutableString alloc] init];}}- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{if([elementName isEqualToString:@"item"]){[rssList addObject:currentItem];[currentItem release];}else if (currentContents && currentItem){[currentItem setObject:currentContents forKey:elementName];[currentContents release];currentContents = nil;}}- (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock{if(currentItem && currentContents){currentContents = [[NSMutableString alloc] initWithData:CDATABlock encoding:NSUTF8StringEncoding];}}- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{if(currentItem && currentContents){[currentContents appendString:string];}}/*- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated];}*//*- (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated];}*//*- (void)viewWillDisappear:(BOOL)animated {[super viewWillDisappear:animated];}*//*- (void)viewDidDisappear:(BOOL)animated {[super viewDidDisappear:animated];}*//* // Override to allow orientations other than the default portrait orientation.- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {// Return YES for supported orientations.return (interfaceOrientation == UIInterfaceOrientationPortrait);} */#pragma mark -#pragma mark Table view data source// Customize the number of sections in the table view.- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1;}// Customize the number of rows in the table view.- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [rssList count];}// Customize the appearance of table view cells.- (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 = [[rssList objectAtIndex:indexPath.row] objectForKey:@"title"]; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; return cell;}/*// Override to support conditional editing of the table view.- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the specified item to be editable. return YES;}*//*// Override to support editing the table view.- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { // Delete the row from the data source. [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; } else if (editingStyle == UITableViewCellEditingStyleInsert) { // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view. } }*//*// Override to support rearranging the table view.- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {}*//*// Override to support conditional rearranging of the table view.- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the item to be re-orderable. return YES;}*/#pragma mark -#pragma mark Table view delegate//当点击cell后利用 NSNotificationCenter将消息传递给 DetailViewController- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSString *des = [[rssList objectAtIndex:indexPath.row]objectForKey:@"description"]; DetailViewController *detailView = [[DetailViewController alloc] init]; NSLog(@"%@", self.navigationController.view); [[self navigationController] pushViewController:detailView animated:YES]; [[NSNotificationCenter defaultCenter] postNotificationName:@"onClicked" object:des]; [detailView release];}#pragma mark -#pragma mark Memory management- (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Relinquish ownership any cached data, images, etc that aren't in use.}- (void)viewDidUnload { // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand. // For example: self.myOutlet = nil;}- (void)dealloc {[rssList release]; [super dealloc];}@end
DetailViewController (详细展示页)
//// DetailViewController.m// InternetNews//// Created by zhang peng on 13-4-16.////#import "DetailViewController.h"#import "RootViewController.h"#import "InternetNewsAppDelegate.h"@implementation DetailViewController- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 300, 800)]; label.numberOfLines = 10; InternetNewsAppDelegate *del = [(InternetNewsAppDelegate *)[UIApplication sharedApplication] delegate]; NSLog(@"%@", self.view); [self.view addSubview:label]; //label.text = del.des; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(test:) name:@"onClicked" object:nil]; } return self;}- (void) test:(NSNotification*) notification{ NSLog(@"%@", notification); label.text = notification.object; [label sizeToFit];}- (void)viewDidLoad{ [super viewDidLoad];// Do any additional setup after loading the view.}- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}/*// Only override drawRect: if you perform custom drawing.// An empty implementation adversely affects performance during animation.- (void)drawRect:(CGRect)rect{ // Drawing code}*/@end
- ios 简单的rss 解析应用demo
- RSS解析技术的应用
- RSS解析新浪新闻IOS
- RSS FEED的应用
- 简单的rss阅读器
- 简单的RSS阅读器
- 简单的RSS技巧
- IOS开发中rss解析数据解析
- 解析xml数据的简单demo
- Kissxml 解析 XML数据的简单Demo
- 对象池的应用的简单Demo
- MVVM在iOS应用的Demo
- 简单监测iOS卡顿的demo
- 基于iOS 的 VLC简单 Demo
- 基于java的RSS在线订阅demo
- 基于java的RSS在线订阅demo
- iOS滤镜简单demo
- IOS 应用的架构解析
- C语言顺序栈
- ssh 三个框架的拦截器
- ios开发之何时用delegate,何时用notification?
- 我也来说struts2乱码问题
- 大规模问题求解
- ios 简单的rss 解析应用demo
- 关于多重继承时继承顺序的一点体会
- MyEclipse8.5+Tomcat6.0.26+JDK1.6部署
- 嗨。
- db2递归实现字符串连接
- #include,#import,@class的区别 .....
- matlab 编程小技巧积累
- Unity3d 通过代码手动创建button(不用GUI自带的button以及其他插件)
- Grizzly目前版本相对于Folsom的变更