iPhone开发:UIScrollView分页算法 [iPhone开发]
post by 朦朧中的罪惡 / 2010-2-22 20:09 Monday
在使用 UIScrollView 分页的时候我们如何确定当前是第几页?
首先需要开启分页设置
scrollView.pagingEnabled = YES;
然后我们在委托的类上实现以下方法
- (void) scrollViewDidScroll:(UIScrollView *)sender {
// 得到每页宽度
CGFloat pageWidth = sender.frame.size.width;
// 根据当前的x坐标和页宽度计算出当前页数
int currentPage = floor((sender.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
}
标签: Objective-c iPhone
iPhone开发:通过NSURLRequest获得服务器返回的http header和http status [iPhone开发]
post by 朦朧中的罪惡 / 2010-2-21 12:22 Sunday
同步访问时的取法
NSURL *url = [NSURL URLWithString:@"http://www.test.com"];
NSURLRequest *request = [NSURLRequest requestWithURL: url];
NSHTTPURLResponse *response;
[NSURLConnection sendSynchronousRequest: request returningResponse: &response error: nil];
if ([response respondsToSelector:@selector(allHeaderFields)]) {
// 取得所有的请求的头
NSDictionary *dictionary = [response allHeaderFields];
NSLog([dictionary description]);
// 取得http状态码
NSLog(@"%d",[response statusCode]);
}
异步访问时则要实现委托的一个方法
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
// 注意这里将NSURLResponse对象转换成NSHTTPURLResponse对象才能去
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
if ([response respondsToSelector:@selector(allHeaderFields)]) {
NSDictionary *dictionary = [httpResponse allHeaderFields];
NSLog([dictionary description]);
NSLog(@"%d",[response statusCode]);
}
}
标签: Objective-c iPhone
iPhone应用程序取得程序关闭事件的方法 [iPhone开发]
post by 朦朧中的罪惡 / 2010-2-8 18:34 Monday
非常简单,在你的AppDelegate对象中实现以下方法
- (void) applicationWillTerminate:(UIApplication *)application {
// 在这里完成程序将要关闭时的事情
}
标签: Objective-c iPhone


