objective c - Why can't I increment the variable one by one? -
whenever click button flipbutton
once, variable curpage
added 4. want increment one. tell me wrong? thanks
- (void)viewdidload { [super viewdidload]; // additional setup after loading 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); }
my guess because put asterisk after int
when declaring curpage
:
int *curpage;
that's reason why compiler insisted on adding (int)
in front of curpage
when passing stringwithformat:
this declares integer pointer, not integer. pointers increment size of whatever point to, on platforms 32-bit int
s increment 4 (the number of bytes taken 32 bits). not need asterisks when declaring variables of primitive types.
Comments
Post a Comment