UiTableView里面有自定义的UITableViewCell

时间:2014-07-16 15:55:08

标签: ios objective-c uitableview

我有一个UITableView,其中显示了另一个UITableViewCell中嵌入的自定义UITableView

自定义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 = @&#34; 1 margherita,2 napoletana&#34 ;;

- (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;,它就有用。

1 个答案:

答案 0 :(得分:0)

我自己回答。问题是将字符串从类传递给类UITableViewCell,我解决了在UITableView中使用[[NSUserDefaults standardUserDefaults] ..保存字符串,除了字符串和自定义uitablevievcell recoveries中的字符串。 所以它有效。但我认为这不是最好的编程方式!

相关问题