使用addSubView
更改容器视图时,我遇到了一个奇怪的错误,UITableView的内容消失了。
这个UITableView是动态的,我是从数组中设置单元格的。目前没有使用数组的内容,它只计算数组的长度并生成该数量的单元格。
从start of this video可以看出,表视图在第一个视图中加载正常。但是当我将容器视图的内容更改为另一个视图然后再返回时,单元格似乎加载,然后消失!
我使用自定义Segue使用以下代码更改菜单按钮点击次数
-(void) perform {
HomeViewController *src = (HomeViewController *)[self sourceViewController];
UIViewController *dst = (UIViewController *)[self destinationViewController];
//Clear view of all subviews
for (UIView *view in src.placeholderView.subviews) {
[view removeFromSuperview];
}
//save destination
src.currentViewController = dst;
//set placeholderOutlet to destination
[src.placeholderView addSubview:dst.view];
}
UITableViewController中的代码如下。
- (void)viewDidLoad {
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
NSMutableArray *thisBlocks = [NSMutableArray arrayWithCapacity:7];
Blocks *block = [[Blocks alloc] init];
block.ID = @"232323";
block.Name = @"128 Some Road";
[thisBlocks addObject:block];
block = [[Blocks alloc] init];
block.ID = @"140332";
block.Name = @"12 Another Road";
[thisBlocks addObject:block];
block = [[Blocks alloc] init];
block.ID = @"889752";
block.Name = @"Quadrant Square";
[thisBlocks addObject:block];
block = [[Blocks alloc] init];
block.ID = @"1403323";
block.Name = @"12 Some Road";
[thisBlocks addObject:block];
block = [[Blocks alloc] init];
block.ID = @"8897522";
block.Name = @"Quadrant Square";
[thisBlocks addObject:block];
block = [[Blocks alloc] init];
block.ID = @"1403392";
block.Name = @"12 Another Road";
[thisBlocks addObject:block];
block = [[Blocks alloc] init];
block.ID = @"8897520";
block.Name = @"Quadrant Square";
[thisBlocks addObject:block];
self.blocks = thisBlocks;
//NSLog(@"array: %@", self.blocks);
//NSLog(@"Rows : %lu", (unsigned long)[self.blocks count] );
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return [self.blocks count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BlockCell"];
return cell;
}
这真让我难过。有什么想法吗?
答案 0 :(得分:1)