I have a UITableView
that shows a custom UITableViewCell
embedded in another UITableView
.
The class of the custom UITableViewCell
is:
@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
class 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;
}
Running the application stops, why? It works if I delete cell.ordine = ordine_1;
.
I answer myself. the problem is to pass the string from a class to a class UITableViewCell, I solved save the string with [[NSUserDefaults standardUserDefaults] .. in UITableView except the string and the string in the custom uitablevievcell recoveries. so it works. But I do not think is the best way to program!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.