ITEEDU

iPhone电子书架加载书架操作笔记

在公司里做的一个iPhone小软件,即在上一次我们已经介绍的iPhone书架的基础上,来实现点击书架上某本书的按钮,让其根据tag值来加载相应的书籍的首页内容。

比如点击了“宝宝喂养”这边书,则显示如图1所示:

图1

iPhone书架中通过webview加载书籍的内容的实现代码

在原有的iPhone书架bookself工程中新建一个类:pageView,然后在bookselfViewController.m中添加import “pageView.h”,将原有的点击动作函数重新修改为:

-(void)btn:(id)sender
{
    UIButton *cellView = (UIButton *)sender;
    NSLog(@"current tag=%d",cellView.tag);//将v.tag作为各种书籍首页的索引值
    pageView *webView = [[pageView alloc] init];
    
    webView.index = cellView.tag;//index是webView的一个全局变量
    [self presentModalViewController:webView animated:YES];  //点击完毕后,将激另一个视图的显示         
    
}

注意presentModalViewController方法!

pageView.h:

#import <UIKit/UIKit.h>

@interface pageView : UIViewController<UIWebViewDelegate>
{
    UIWebView *webView;
    UIButton *backBn;
    UIView *opaqueview;
    UIActivityIndicatorView *activityIndicator;
    NSInteger index;
    NSInteger pageIndex;
}

@property(nonatomic,retain)UIWebView *webView;
@property(nonatomic,retain)UIButton *backBn;
@property(nonatomic,retain)UIView *opaqueview;
@property(nonatomic,retain)UIActivityIndicatorView *activityIndicator;
@property(nonatomic,assign)NSInteger index;
@property(nonatomic,assign)NSInteger pageIndex;

@end