objective c - UITableview - Can't Reload data -


i'm noob in obj-c programming. i'm making ipad application composed of viewcontroller shows me 2 text boxes , button in upper side , make sum.

in same viewcontroller, have tableview , button. tableview shows me element, i'd want refresh list clicking button.

the function linked @ button refresh list ( touch down event ) called " listapdf " .

viewcontroller.h

#import <uikit/uikit.h>  @interface vpviewcontroller : uiviewcontroller <uitableviewdelegate, uitableviewdatasource> {     iboutlet uitextfield *txtprimoaddendo ;     iboutlet uitextfield *txtsecondoaddendo ;     iboutlet uilabel *lbltotale ;     iboutlet uitableview *tabella;     nsmutablearray *lista;    }  @property (nonatomic, retain) iboutlet uitextfield *txtprimoaddendo; @property (nonatomic, retain) iboutlet uitextfield *txtsecondoaddendo; @property (nonatomic, retain) iboutlet uilabel *lbltotale; @property (nonatomic, retain) iboutlet uitableview *tabella; @property (nonatomic, retain) nsmutablearray *lista;  -(ibaction)somma ; -(ibaction)listapdf;  @end 

viewcontroller.m

    #import "vpviewcontroller.h"      @interface vpviewcontroller ()      @end      @implementation vpviewcontroller      -(void)somma {      int x = [[txtprimoaddendo text] intvalue];     int y = [[txtsecondoaddendo text] intvalue];     int somma = x + y ;      nsstring *totale = [nsstring stringwithformat:@"la somma fa : %d", somma];      [lbltotale settext:totale];     [lbltotale sethidden:false];       }     - (void)listapdf {      int contatore = 1;      nsarray *dirfiles = [[nsfilemanager defaultmanager] contentsofdirectoryatpath:[[nsbundle mainbundle] resourcepath] error: nil];     (int = 0; < dirfiles.count ; i++) {          nsstring *files = dirfiles[i];         int indice = files.length - 4 ;         nsstring *extension = [files substringfromindex:indice];          if([extension  isequal: @".pdf"]) {              nslog(@"********* file pdf : %@", files);             [lista insertobject:files atindex:contatore];             contatore++;         }     }     [tabella reloaddata];      }      - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section     {         return [lista count];     }     - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath     {     static nsstring *simpletableidentifier = @"cellid";      uitableviewcell *cell = [tabella dequeuereusablecellwithidentifier:simpletableidentifier];      if (cell == nil) {         cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:simpletableidentifier];     }     cell.imageview.image = [uiimage imagenamed:@"pdf.png"];     cell.textlabel.text = [lista objectatindex:indexpath.row];     return cell;     }       - (void)viewdidload     {         tabella.delegate = self;         tabella.datasource = self;          tabella = [[ uitableview alloc] init];         lista = [[nsmutablearray alloc] init];          [lista insertobject:@"first element" atindex:0];       [super viewdidload];     // additional setup after loading view, typically nib.     }      - (void)didreceivememorywarning     {     [super didreceivememorywarning];     // dispose of resources can recreated.     }  -(bool)textfieldshouldreturn:(uitextfield *)textfield{     [textfield resignfirstresponder];     return yes; }  @synthesize lbltotale; @synthesize txtprimoaddendo; @synthesize txtsecondoaddendo; @synthesize tabella; @synthesize lista;   @end 

thanks

i have tried code is.

why initializing uitableview object in viewdidload. doesn't need allocated if adding on xib file. if creating uitableview programmatically required. comment/remove initializing line , tableview's delegate methods called.

and in 'listapdf' function no items being added array 'lista', that's why no new entry visible in uitableview.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

debian - 500 Error upon login into Plesk Admin - auth.php3? -