Добрый день, у меня проблема и надеюсь, что вы можете мне посоветовать. Прежде всего, я прошу прощения, если что-то подобное уже было задано, я думаю, что нет, но, тем не менее, простить ошибки новичка
Проект, которым я занимаюсь, - это TabBarViewController с двумя контроллерами.
Тот, который в основном способен захватить штрих-код и сделать вызов веб-службы со штрих-кодом, чтобы получить элемент с сервера. Затем этот элемент нужно отобразить на другом контроллере.
Моя проблема в том, что я не знаю, как передать полученный элемент в мой пользовательский UITableViewController или каков наилучший способ добиться этого.
Это интерфейс, который может захватывать штрих-код и подключаться к веб-сервису
#import <UIKit/UIKit.h>
#import "MBProgressHUD.h"
#import "ListaItemsViewController.h"
@interface ViewController : UIViewController < ZBarReaderDelegate,NSXMLParserDelegate >
{
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
а это интерфейс
#import <UIKit/UIKit.h>
@interface ListaItemsViewController : UITableViewController
{
// the item list
NSMutableArray * listaItems;
}
@property(nonatomic,strong) NSMutableArray * listaItems;
@end
это файл реализации:
#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
Каков наилучший способ добиться этого, лучшая практика?
Опять же, извините, если это слишком просто для вас, ребята, но я только начал с этой технологии.
Привет