tags:

views:

26

answers:

1

Hi, iam going to change my UIWebView files via UISwipeGuesture but have problem :

i have 100 HTML files that loaded on UIWebView , so i want implement something like this : if user swipes the view my webView will load next html file but the problem is my code just load first HTML file :

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];
+1  A: 

[NSString stringWithFormat:@"file%d",+1] is always going to return the string file1, so you're always loading file1.html.

Do you mean to be using a counter or index instead of the number 1?

EDIT: More code. This isn't how I'd recommend implementing this, but it should give you an idea and it's relatively compact. (I'd use an ivar or property to track the current file index.)

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];
Robot K
I mean when user swipe right to left UIwebview load file2.html then file3, then file4 and .....
Momeks
Thank you Robot K , works great , but with currentIndex = 0 ; , my files goes back web 1 , doesn't continue form the last file !
Momeks