网络请求 新闻翻翻看 (OC UINavigationController NSURL UITableView UIWebView )
来源:互联网 发布:mysqldump恢复数据库 编辑:程序博客网 时间:2024/05/16 11:27
AppDelegate.h strong---retain
AppDelegate.m 声明头文件 #import "MainViewController.h"
{
MainViewController *mainVC = [[MainViewController alloc] init];
UINavigationController *naviVC = [[UINavigationController alloc] initWithRootViewController:mainVC];
self.window.rootViewController = naviVC;
[mainVC release];
[naviVC release];
[_window release];
}
- (void)dealloc
{
[_window release];
[super dealloc];
}
MainViewController.h <UITableViewDataSource, UITableViewDelegate> // UITableView 的两个方法
三个属性
@property (nonatomic, retain)UITableView *tableView;
@property (nonatomic, retain)NSMutableData *data;
@property (nonatomic, retain)NSMutableArray *array;
MainViewController.m #import "FirstViewController.h"
- (id)
{
self.title = @"北京新闻";
// 初始化方法
[self songxueqian];
}
- (void)viewDidLoad
{
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0 , 320, 480) style:UITableViewStylePlain];
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.view addSubview:self.tableView];
[self.tableView release];
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cellQQQ"];
}
- (NSInteger)tableVIew:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
[return self.array count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *str = @"cellQQQ";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:str];
cell .textLabel.text = [[self.array objectAtIndex:indexPath.row] objectForKey:@"title"];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
FirstViewController *firstVC = [[FirstViewController alloc] init];
firstVC.string = [[self.array objectAtIndex:indexPath.row] objectForKey:@"newsUrl"];
[self.navigationController pushViewController:firstVC animated:YES];
[firstVC release];
}
- (void)songxueqian
{
NSString *str = @"http://ipad-bjwb.bjd.com.cn/DigitalPublication/publish/Handler/APINewsList.ashx";
[NSURL *url = NSURL URLWithString:str];
NSMutableURLRequest *request = NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60.f];
[request setHTTPMethod:@"POST"];
NSString *bodyStr = @"date=20131129&startRecord=1&len=30&udid=1234567890&terminalType=Iphone&cid=213";
NSData *data = [bodyStr dataUsingEncoding:NSUTF8StingEncoding];
[request setHTTPBody:data];
NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
id object = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
self.array = [object objectForKey:@"news"];
[self.tableView reloadData];
}];
}
FirstViewController.h
@property (nonatomic, retain)UIWebView *webView;
@property (nonatomic, copy)NSMutableString *string;
FirstViewController.m
- (id)
{
self.webView = [[UIWebView alloc] init];
}
- (void)viewDidLoad
{
self.webView = [UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
NSURL *url = [NSURL URLWithString:self.string];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.f];
[self.webView loadRequest:request];
[self.view addSubview:self.webView];
[self.webView release];
- 网络请求 新闻翻翻看 (OC UINavigationController NSURL UITableView UIWebView )
- NSURL网络请求相关的错误
- 原生 NSURL 网络请求 GET POST
- iOS网络请求——NSURL
- 网络编程知识总结 之 NSURL网络请求
- IOS开发之NSURL网络请求,同步异步,GET,POST
- iOS原生网络请求使用(NSURL,NSURLRequest/NSMutableURLRequest,NSURLConnection)
- NSData NSURL 字符串网络请求的时候 互相转换
- UIWebView / NSURL / NSBoundle 相关应用
- UIWebView/NSURL/NSBoundle相关应用
- OC学习----NSURL
- OC中的NSURL
- 使用UIWebView与html实现网络请求
- OC下几种网络请求方式
- 基于OC的网络请求
- iOS 设置UIWebView允许请求https网络请求
- UINavigationController,UITableview的使用
- 新闻客户端04 - 请求网络数据
- <收藏> 我的算法学习之路
- RUDP之二 —— Sending and Receiving Packets
- Swift类与结构体
- elasticsearch中文分词(mmseg)——手动添加词典
- 图像处理之边缘检测概述
- 网络请求 新闻翻翻看 (OC UINavigationController NSURL UITableView UIWebView )
- 玩转Android Camera开发(四):预览界面四周暗中间亮,只拍摄矩形区域图片(附完整源码)
- wordpress Google AdSense 谷歌adsense插件
- 【图】最小费用最大流MCMF
- ASP.NET中Request.ApplicationPath、Request.FilePath、Request.Path、.Request.MapPath、
- C++ explicit关键字应用方法详解
- 好博客收藏
- 5个Xcode开发调试技巧
- struts2文件过滤拦截器fileUpload以及各种文件类型