2012-02-21 13 views
0

おはようございます、私には問題があり、あなたに助言してもらいたいと思います。まず最初に、このようなことが既に尋ねられている場合は謝罪しますが、私は思っていませんが、まだルーキーミスを許してください。TableViewControllerの列を追加および削除する最も良い方法は何ですか?

私が行っているプロジェクトは2つのコントローラを備えたTabBarViewControllerです。 基本的にバーコードをキャプチャして、バーコードでWebサービスを呼び出して、サーバーからアイテムを取得できます。そのアイテムは、他のコントローラに表示されます。

私の問題は、取得したアイテムをカスタムUITableViewControllerに渡す方法、またはこれを達成するための最良の方法です。

これは、バーコードをキャプチャし、Webサービスに

#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 

これを達成する最良の方法は、ベストプラクティスですか?

ご迷惑をおかけいたしますが、この技術を使い始めるのはごめんなさい。 よろしく

+0

質問のタイトルと実際の質問が同じではありませんか?どちらが正しいですか? – user523234

+0

返信用のThxと不便のための私の謝罪です。私の問題は、取得方法を渡す方法がわかりません。私のカスタムUITableViewControllerに項目を追加するか、これを達成するための最良の方法です。最初のコントローラーとIDを使用して取得します。カスタムtaに項目を追加するブリーク。 – aironman

+0

私はあなたの質問だと思ったものを置いた。しかし今は、一度に1つのアイテムを渡すのか、アイテムの配列を渡すのかは分かりません。 – user523234

答えて

0

アニメーションなしで行を削除したい場合は、データソース配列listaItemsからエントリを削除し、テーブル上で-reloadDataを実行します。

0

またのUITableView方法を見ることができます:私が集まるところでは、あなたViewController.hファイルから与えられた情報で

- (void)deleteRowsAtIndexPaths: (NSIndexPath) indexPath withRowAnimation: (UITableViewRowAnimation)animation; 
0

、あなたのViewControllerはListaItemsViewControllerの瞬間はlistaItemsViewControllerを呼びかけています。残念ながら

listaItemsViewController.listaItems = retrieveItems; // or self.retrieveItems where retrievedItems is the array of items that you have retrieved from the web server. 

、私は変数のどのあなたを見つけ出すことができませんでした:あなたはこのようなlistaItemsに取得したアイテムを割り当てることができるようにイヴァーは、あなたがlistaItemsViewControllerの瞬間をインスタンス化した後(、ListaItemsViewControllerでlistaItemsが呼ばれています

+0

再び、返信用に! – aironman

+0

こんにちは、再び応答のためのthx!あなたはほとんどすべてを理解しました。私のViewControllerはlistaItemsViewControllerというListAItemsViewControllerへの瞬間を持ち、その中にlistaItemsというNSMutableArrayがあります。これは私がやろうとしていることです: – aironman

+0

私はあなたのやり方を試しましたが、うまくいきません。不便をおかけして申し訳ありません。/ * NSMutableArray * lista = [[NSMutableArray alloc] initWithObjects:@ "itemcito1"、@ "itemcito2"、nil]; if(!listaItemsViewController) listaItemsViewController = [[ListaItemsViewController alloc] init]; listaItemsViewController.listaItems = lista; //バックエンドでのバックエンドの問い合わせ先 NSLog(@ "listaItemsにアイテムを追加..."); **/ – aironman

関連する問題