1
每當我點擊按鈕flipButton
一次,變量curPage
添加4.我想增加一個。有人能告訴我什麼是錯的嗎? 感謝爲什麼我不能逐個遞增變量?
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
curPage = 0 ;
NSString * dic = nil;
if ((NSInteger)tempIndex == 0) {
type = @"Fire_";
dic = [NSString stringWithFormat:@"%@%d",type,0];
}
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:dic ofType:@"htm"];
NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
[contentWebView loadHTMLString:htmlString baseURL:nil];
UIBarButtonItem *flipButton = [[UIBarButtonItem alloc]
initWithTitle:@"Flip"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(flipView)];
self.navigationItem.rightBarButtonItem = flipButton;
}
-(IBAction)flipView{
curPage = curPage + 1;
NSString *path = [NSString stringWithFormat:@"%@%d",type,(int)curPage];
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:path ofType:@"htm"];
NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
[contentWebView loadHTMLString:htmlString baseURL:nil];
NSLog(path);
}
curPage的數據類型是什麼?我看你把它投給了一個int。你不應該那樣做。 –
另外,請嘗試放置'NSLog(@「%@」,curPage);' 'curPage = curPage + 1;' –
後面的flipView函數應該是IBAction類型嗎?我認爲IBAction是爲故事板設計的。但是,在上面的代碼中,您正在將flipView與您以編程方式創建的按鈕相關聯 – Max