我在一个 viewController 和一个菜单按钮中有两个 TableView 。 最初只显示 tableView1,当我按下菜单按钮时,第二个 TableView 应该出现并且 tableView1 仍然存在。
我阅读并实现了我发现的内容,但没有结果。
两个 TableView 都出现了,但是数据是一样的,我不想这样。我试图这样做:
- (void) viewDidLoad {
tableView.hidden = NO;
tableViewMenu.hidden = YES;
tableView.delegate = self;
tableView.dataSource = self;
tableViewMenu.delegate = self;
tableViewMenu.dataSource = self;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (tableView == tableView) {
return 30;
}
else {
return 4;
}
}
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableView == tableView) {
static NSString *CellIdentifier1 = @"Cell1";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] ;
}
cell.textLabel.text = @"Table 1";
NSLog(@"1here is%i %@",indexPath.row,cell.textLabel.text);
return cell;
} else {
static NSString *CellIdentifier2 = @"Cell2";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier2] ;
}
cell.textLabel.text = @"Table 2";
return cell;
}
}
int i = 1;
- (void) showMenu {
//slide the content view to the right to reveal the menu
//tableView.hidden = NO;
tableViewMenu.hidden = NO;
NSLog(@"Display");
if (i == 1) {
[UITableView animateWithDuration:.25
animations:^{
[tableView setFrame:CGRectMake(tableViewMenu.frame.size.width, tableView.frame.origin.y, tableView.frame.size.width, tableView.frame.size.height)];
[testView setFrame:CGRectMake(tableViewMenu.frame.size.width, testView.frame.origin.y, testView.frame.size.width, testView.frame.size.height)];
}];
i = 0;
} else {
[UIView animateWithDuration:.25
animations:^{
[tableView setFrame:CGRectMake(0, tableView.frame.origin.y, tableView.frame.size.width, tableView.frame.size.height)];
[testView setFrame:CGRectMake(0, testView.frame.origin.y, testView.frame.size.width, testView.frame.size.height)];
tableViewMenu.hidden=YES;
}];
i = 1;
}
}
最佳答案
我想问题出在这条线上:
if(tableView==tableView)
您应该将 tableview
参数与您的 @property
进行比较。
如果参数和 iVar 具有相同的名称,则参数将覆盖方法范围内的 iVar。
if (tableview == self.tableView)
关于ios - 一个 View Controller 中的两个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28495997/