[NSString stringWithFormat:@"file%d",+1]
总是返回字符串
file1
,所以你总是在加载
file1.html
.
你的意思是使用计数器或索引而不是数字1?
编辑:更多代码。这不是我建议的实现方法,但是它应该给你一个概念,而且它相对紧凑。(我将使用ivar或属性跟踪当前文件索引。)
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];