繁体   English   中英

自定义UITableViewCell中的UiTableView

[英]UiTableView inside custom UITableViewCell

我有一个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 = @“ 1 margherita,2 napoletana”;

- (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;

我回答自己。 问题是将字符串从类传递到类UITableViewCell,我解决了用[[NSUserDefaults standardUserDefaults] ..将字符串保存在UITableView中的问题,但该字符串和自定义uitablevievcell恢复中的字符串除外。 这样就可以了。 但是我不认为这是最好的编程方式!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM