Note that there are some explanatory texts on larger screens.

plurals
  1. POwhat is the best way to add and delete columns in a TableViewController?
    primarykey
    data
    text
    <p>Good afternoon, I have a problem and hope you can advise me. First of all I apologize if something like this has already been asked, I think not, but still, forgive rookie mistakes</p> <p>The project I'm doing is a TabBarViewController with two controllers. One that basically is able to capture a bar code and make a call to a Web service with the bar code to get me the item from the server. That item then want to show on the other controller.</p> <p>My problem is i don't know how to pass the retrieved item to my custom UITableViewController, or which is the best way to achieve this.</p> <p>This is the interface able to capture a bar code and connect to a web service</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; #import "MBProgressHUD.h" #import "ListaItemsViewController.h" @interface ViewController : UIViewController &lt; ZBarReaderDelegate,NSXMLParserDelegate &gt; { IBOutlet UILabel * resultText; ListaItemsViewController * listaItemsViewController; MBProgressHUD * HUD; NSMutableData * xmlData; //neccesary to parse the possible error NSMutableString * faultString; BOOL esperandoFaultString; //neccesary to parse message from logIn and logOut methods webservice BOOL esperandoReturn; NSMutableString * returnString; //neccesary to parse and save an item BOOL esperandoItem; BOOL esperandoDescripcionItem; BOOL esperandoPrecioItem; BOOL esperandoNumTotalItem; NSMutableString * descripcionItem; NSMutableString * precioItem; NSMutableString * numeroTotalItem; NSXMLParser * parser; } @property (nonatomic,strong) MBProgressHUD * HUD; @property (nonatomic, retain) IBOutlet UILabel * resultText; @property(nonatomic,strong) NSMutableData * xmlData; @property(nonatomic,strong) NSMutableString * faultString; @property(nonatomic,strong) NSMutableString * returnString; @property(nonatomic,strong) NSMutableString * descripcionItem; @property(nonatomic,strong) NSMutableString * precioItem; @property(nonatomic,strong) NSMutableString * numeroTotalItem; @property(nonatomic,strong) NSXMLParser * parser; @property(nonatomic,strong) ListaItemsViewController * listaItemsViewController; - (IBAction) scanButtonTapped; - (IBAction)esconderTeclado:(id)sender; - (IBAction)mostrarTeclado:(id)sender; @end </code></pre> <p>and this is the interface </p> <pre><code> #import &lt;UIKit/UIKit.h&gt; @interface ListaItemsViewController : UITableViewController { // the item list NSMutableArray * listaItems; } @property(nonatomic,strong) NSMutableArray * listaItems; @end </code></pre> <p>this is the implementation file:</p> <pre><code> #import "ListaItemsViewController.h" #import "CaracteristicasItemViewController.h" @implementation ListaItemsViewController @synthesize listaItems; - (id)initWithStyle:(UITableViewStyle)style { NSLog(@"ListaItemsViewController. initWithStyle..."); self = [super initWithStyle:style]; if (self) { // Custom initialization } return self; } - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } #pragma mark - View lifecycle - (void)viewDidLoad { NSLog(@"ListaItemsViewController. viewDidLoad..."); **//how do i create this item list with the items passed via web service?** listaItems = [[NSMutableArray alloc] initWithObjects:@"item1",@"item2",@"item3", nil]; [super viewDidLoad]; self.navigationItem.rightBarButtonItem = self.editButtonItem; } - (void)viewDidUnload { [super viewDidUnload]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; } - (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // Return the number of rows in the section. NSLog(@"[listaItems count]: %d",[listaItems count]); return [listaItems count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"celda"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } // Configure the cell... cell.textLabel.text = [listaItems objectAtIndex:[indexPath row]]; cell.detailTextLabel.text = [listaItems objectAtIndex:[indexPath row]]; NSLog(@"cell: %@",cell.textLabel.text); return cell; } // Override to support conditional editing of the table view. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the specified item to be editable. return YES; } // Override to support editing the table view. - (void)tableView:(UITableView *)tableView commitEditingStyle: (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { **when i try to delete some row, the app crash, check!!** NSLog(@"commitEditingStyle..."); [tableView beginUpdates]; if (editingStyle == UITableViewCellEditingStyleDelete) { // Delete the row from the data source [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; //[listaItems delete:[NSArray arrayWithObject:indexPath]]; } [tableView endUpdates]; NSLog(@"end commitEditingStyle..."); } #pragma mark - Table view delegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // Navigation logic may go here. Create and push another view controller. NSLog(@"didSelectRowAtIndexPath indexPath.row: %d",indexPath.row); CaracteristicasItemViewController *caracteristicas = [[CaracteristicasItemViewController alloc] initWithNibName:@"CaracteristicasItemViewController" bundle:Nil]; [self.navigationController pushViewController:caracteristicas animated:YES]; } @end </code></pre> <p>Whats the best way to achieve this, the best practice?</p> <p>Again, sorry if this is too easy for you guys, but I just started with this technology. Regards</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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