2014-07-16 96 views
1

我有一個UITableView顯示一個自定義UITableViewCell嵌入在另一個UITableViewUiTableView內部自定義UITableViewCell

類定製UITableViewCell的是:

@interface XYZcustomtakeawayTableViewCell: UITableViewCell <UITableViewDataSource,UITableViewDelegate> 
{ 
     NSString * order; 
} 

@property (strong, nonatomic) IBOutlet UITableView * tableviewinside; 
@property (nonatomic, retain) NSString * order; 

@end 




#import "XYZcustomtakeawayTableViewCell.h" 

@implementation {XYZcustomtakeawayTableViewCell 
{ 
     NSMutableArray * dataArray; 
} 

@synthesize tableviewinside, order; 

- (id) initWithStyle: (UITableViewCellStyle) style reuseIdentifier: (NSString *) reuseIdentifier: (NSString *) Order 
{ 
     self = [super initWithStyle: style reuseIdentifier: reuseIdentifier]; 
     if (self) { 
         // Initialization code     
     } 
     return self; 
} 

- (void) awakeFromNib 
{ 
     // Initialization code 
     
     
    
     dataArray = [[order componentsSeparatedByString: @ ""] mutableCopy]; 

     self.tableviewinside.delegate = self; 
     self.tableviewinside.dataSource = self; 

} 

- (void) setSelected: (BOOL) selected animated: (BOOL) animated 
{ 
     [super setSelected: selected animated: animated]; 

    // Configure the view for the selected were 
} 

- (NSInteger) numberOfSectionsInTableView: (UITableView *) tableView 
{ 
     return 1; 
} 

- (NSInteger) tableView: (UITableView *) tableView numberOfRowsInSection: (NSInteger) section 
{ 
     dataArray = [[order componentsSeparatedByString: @ ""] mutableCopy]; 
     dataArray.count return; 
} 

- (UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath 
{ 
     UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: @ "cell"]; 
     if (cell == nil) 
     { 
         cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: @ "cell"]; 
     } 
     cell.textLabel.text = [dataArray objectAtIndex: indexPath.row]; 
     
     return cell; 
} 

@end 

類的UITableViewController

import <UIKit/UIKit.h> 


@interface XYZGestisciTakeAwayTableViewController: UITableViewController 

@end 

的NSString * ordine_1 = @ 「1個瑪格麗塔,2塔那」;

- (UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath 
{ 
     static NSString * simpleTableIdentifier = @ "cell"; 
  
     XYZcustomtakeawayTableViewCell * cell = (XYZcustomtakeawayTableViewCell *) [tableView dequeueReusableCellWithIdentifier: simpleTableIdentifier]; 
     
     if (cell == nil) 
     { 
              NSArray * nib = [[NSBundle mainBundle] loadNibNamed: @ "custom_prenotazioni" owner: self options: nil]; 
         cell = [nib objectAtIndex:0]; 
       
     } 
     
     cell.ordine = ordine_1; //FAILURE !!!!!!!!!!!! 
     
     
     
     
     return cell; 
} 

運行應用程序會停止,爲什麼? 它工作,如果我刪除cell.ordine = ordine_1;

+0

你在你的自定義單元上聲明'ordine'在哪裏?我只能看到'order'和'tableviewinside'的屬性。 – Stonz2

+0

它崩潰還是停止?還有@ Stonz2說的 – random

回答

0

我自己回答。問題是將字符串從一個類傳遞給一個類UITableViewCell,我解決了在UITableView中保存字符串[[NSUserDefaults standardUserDefaults] ..除了字符串和自定義uitablevievcell恢復中的字符串。 所以它的工作原理。但我不認爲是編程的最佳方式!