ios - how to store NSString in Stack -


i create stack class in program want store nsstring value in that. stack class :

@interface stack : nsobject - (void)push:(id)obj; - (id)pop; - (bool)isempty; @end @implementation stack {     nsmutablearray *stack; } - (id)init {     self = [super init];        if(self!= nil){         stack = [[nsmutablearray alloc] init];     }     return self; } - (void)push:(id)obj {     [stack addobject:obj]; } - (id)pop {     id lastobj = [stack lastobject];     [stack removelastobject];     return lastobj; } - (bool)isempty {     return stack.count == 0; } @end 

also have class name : tableviewcontroller want when click on cell in tableviewcontroller store cell's id receive url

this code:

- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath  {     // want xcode value xcode2 value push in stack       nslog(@"row in tab : %d",indexpath.row);      if ([folder containsobject:[all objectatindex:indexpath.row]]) {         nsurl *url = [nsurl urlwithstring:[nsstring stringwithformat:@"http://192.168.1.%d/mamal/filemanager.php?dir=%@&folder=%d&id",ip,xcode,indexpath.row]];         nsurlrequest *request = [nsurlrequest requestwithurl:url];         nsurlresponse *response = nil;         nserror *err = nil;         nsdata *data = [nsurlconnection sendsynchronousrequest:request returningresponse:&response error:&err];         nsstring *responsestring = [[nsstring alloc] initwithbytes:[data bytes] length:[data length] encoding:nsutf8stringencoding];         xcode2 = responsestring;          //this new cell's id.i want push value in stack         nslog(@"xcode : %@", xcode2);          [self performseguewithidentifier:@"segue4" sender:self];     }      else     {         [self performseguewithidentifier:@"segue3" sender:self];      } }   

in top code want when click on cell push 2 value in stack (xcode & xcode2) dont know use of stack.

  1. you need variable holds stack.. i'd make member var:

    @implementation tableviewcontroller {     stack *_stack; } ... 
  2. then when cell clicked, push value

    ... if(!_stack)     _stack = [[stack alloc] init]; [_stack push:xcode2]; ...  

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -