我有两个UITableView
,第一个(FirstViewController.h
)是菜单,第二个(SecondViewController.h
)是menuItems。我的问题是,当我从第二个tableView clearColor
制作单元格时,当我从FirstViewController
进行选择时,SecondViewController
上的项目显示为已延迟。
@interface FirstViewController ()
@end
@implementation FirstViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
_items = [[NSMutableArray alloc] init];
[_items addObject:@"Menu1"];
[_items addObject:@"Menu2"];
[_items addObject:@"Menu3"];
[_items addObject:@"Menu4"];
self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@"light.png"]];
self.tableView.backgroundColor = [UIColor clearColor];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [_items count];
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.backgroundColor = [UIColor clearColor];
cell.layer.backgroundColor = [UIColor clearColor].CGColor;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
NSString *item = [_items objectAtIndex:indexPath.row];
[[cell textLabel] setText:item];
cell.textLabel.textColor = [UIColor whiteColor];
return cell;
}
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"MenuItems"]) {
SecondViewController *secondViewController = [segue destinationViewController];
_items = [[NSMutableArray alloc] initWithObjects:@"MenuItem 1", @"MenuItem 2", @"MenuItem 3", @"MenuItem 4", nil];
[secondViewController setItems:_items];
}
}
@end
//--------------------------------------------------------------------------
@implementation SecondViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"light.png"]];
self.tableView.backgroundColor = [UIColor clearColor];
UIBarButtonItem *btnBack = [[UIBarButtonItem alloc] initWithTitle:@"Menu" style:UIBarButtonItemStyleBordered target:self action:@selector(onClick_btnBack:)];
self.navigationItem.leftBarButtonItem = btnBack;
}
-(IBAction)onClick_btnBack:(id)sender {
[self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [_items count];
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
cell.backgroundColor = [UIColor clearColor];
cell.layer.backgroundColor = [UIColor clearColor].CGColor;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
NSString *item = [_items objectAtIndex:indexPath.row];
[[cell textLabel] setText:item];
cell.textLabel.textColor = [UIColor whiteColor];
return cell;
}
@end