Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 在一个UIWebView上加载不同的html文件_Iphone_Sdk_Ios4 - Fatal编程技术网

Iphone 在一个UIWebView上加载不同的html文件

Iphone 在一个UIWebView上加载不同的html文件,iphone,sdk,ios4,Iphone,Sdk,Ios4,我将通过uiwipeguesture更改我的UIWebView文件,但有问题: 我在UIWebView上加载了100个HTML文件,因此我希望实现如下内容: 如果用户滑动视图,my webView将加载下一个html文件,但问题是我的代码只加载第一个html文件: NSString *path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"file%d",+1] ofType:@"html"]; NSF

我将通过
uiwipeguesture
更改我的
UIWebView
文件,但有问题:

我在UIWebView上加载了100个HTML文件,因此我希望实现如下内容: 如果用户滑动视图,my webView将加载下一个html文件,但问题是我的代码只加载第一个html文件:

NSString *path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"file%d",+1] ofType:@"html"];
NSFileHandle *readHandle = [NSFileHandle fileHandleForReadingAtPath:path];

NSString *htmlString = [[NSString alloc] initWithData: 
                        [readHandle readDataToEndOfFile] encoding:NSUTF8StringEncoding];


[self.myWebView loadHTMLString:htmlString baseURL:nil];

[NSString stringWithFormat:@“文件%d”,+1]
总是返回字符串
file1
,因此您总是加载
file1.html

你的意思是使用计数器或索引而不是数字1吗

编辑:更多代码。这不是我建议的实现方式,但它应该给你一个想法,而且相对紧凑。(我会使用ivar或属性跟踪当前文件索引。)

static NSInteger currentIndex=0;
如果(当前索引<99){
currentIndex++;
}
NSString*路径=[[NSBundle mainBundle]路径用于资源:[NSString stringWithFormat:@“文件%d”,currentIndex]类型:@“html”];
NSFileHandle*readHandle=[NSFileHandle fileHandleForReadingAtPath:path];
NSString*htmlString=[[NSString alloc]initWithData:
[readHandle readDataToEndOfFile]编码:NSUTF8StringEncoding];
[self.myWebView加载htmlString:htmlString baseURL:nil];

我的意思是,当用户从右向左滑动UIwebview时,加载file2.html,然后加载file3,然后加载file4和…..谢谢Robot K,效果很好,但currentIndex=0,我的文件追溯到web 1,不会从最后一个文件继续!
static NSInteger currentIndex = 0;
if (currentIndex < 99) {
    currentIndex++;
}
NSString *path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"file%d",currentIndex] ofType:@"html"];
NSFileHandle *readHandle = [NSFileHandle fileHandleForReadingAtPath:path];
NSString *htmlString = [[NSString alloc] initWithData: 
                        [readHandle readDataToEndOfFile] encoding:NSUTF8StringEncoding];
[self.myWebView loadHTMLString:htmlString baseURL:nil];