Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do you reload a tableView in ios6 with a mutable array?
    primarykey
    data
    text
    <p>I have a tableview set up with data from a mutable array but I cannot figure out how to reload it, or even if it's being loaded in the first place.</p> <p>The mutable array is changed when a user presses a button. When I initialize the array with test data, the table view works fine. I figured that I needed to reload the table, but I've been unsuccessful doing it inside cellForRowAtIndexPath. I've also tried to reload by synthesizing the tableView through the .h and reloading after adding to the array from the add button being clicked method (attempts not reflected in code, but if you think I did it wrong go ahead and post the right way).</p> <p>There is no error, but nothing happens when I click the add button.</p> <p>Any help is greatly appreciated.</p> <p>Relevant code:</p> <p>.h:</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface ViewController : UIViewController &lt;UITableViewDelegate, UITableViewDataSource&gt; @property (weak, nonatomic) IBOutlet UITextField *name; @property (weak, nonatomic) IBOutlet UITextField *company; - (IBAction)add:(id)sender; **@property (nonatomic, retain) NSMutableArray *currentNames; @property (nonatomic, retain) NSMutableArray *currentCompanies; @property (nonatomic, retain) NSMutableArray *names; @property (nonatomic, retain) NSMutableArray *companies; @property (weak, nonatomic) IBOutlet UITableView *preExisting;** @end </code></pre> <p>.m:</p> <pre><code>#import "ViewController.h" @interface ViewController () @end @implementation ViewController **@synthesize name, company, currentNames, currentCompanies, names, companies; - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. NSMutableArray *currentNames = [[NSMutableArray alloc] init]; NSMutableArray *currentCompanies = [[NSMutableArray alloc] init]; NSMutableArray *names = [[NSMutableArray alloc] init]; NSMutableArray *companies = [[NSMutableArray alloc] init]; self.preExisting = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStylePlain];** } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { this.tableView = tableView; return [currentNames count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *simpleTableIdentifier = @"SimpleTableItem"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier]; } cell.textLabel.text = [currentNames objectAtIndex:indexPath.row]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView reloadData]; } - (IBAction)add:(id)sender { BOOL exists = [names containsObject:name.text]; if(exists == FALSE){ [currentNames addObject:[name text]]; [currentCompanies addObject:[company text]]; [names addObject:[name text]]; [companies addObject:[company text]]; } else{ [currentNames addObject:[name text]]; [currentCompanies addObject:[company text]]; } [currentNames addObject:[name text]]; **[_preExisting reloadData];** name.text=@""; company.text=@""; } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload