我想使用两个表视图,比如…。。
我正在使用popover控制器
第一个表视图在弹出控制器中,我有两个按钮(添加注释按钮和剩余按钮)当我单击剩余按钮时,我隐藏了第一个表视图并启用了第二个表视图
未调用cellforrowatindexpath的第二个表视图单元格的ut
仅用于它调用的第一个表视图,而不调用第二个表视图
这里我的代码是………。。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView==self.remainderTableView)//second Tbleview {
static NSString *cellIdentifier=@"Celliden";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell==nil) {
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
cell.textLabel.text=@"hhh";
return cell;
}
else if (tableView==self.NotesandRemainderTable)//first Tableview {
static NSString *cellIdentifier = @"bookingCell";
CustomTableViewSwipeCell *cell = (CustomTableViewSwipeCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
NSString *note=[jsondata valueForKey:@"TeacherNotes"];
NSLog(@"teacher notes %@",note);
// if (cell==nil) {
// cell=[[CustomTableViewSwipeCell alloc]init];
// }
// Add utility buttons
NSMutableArray *rightUtilityButtons = [NSMutableArray new];
[rightUtilityButtons sw_addUtilityButtonWithColor:
[UIColor colorWithRed:1.0f green:0.231f blue:0.188 alpha:1.0f]
title:@"Delete"];
_SubjectLabel.text=AppDel.sub;
NSLog(@"the date %@",AppDel.date);
_DateLabel.text=_dateToDisplay;
if (indexPath.section==0)
{
if (indexPath.row==0)
{
cell.Noteslabel.text=note;
}
return cell;
}
if (indexPath.section==1){
cell.Noteslabel.text=[_notesArray objectAtIndex:indexPath.row];
//NSLog(@"notes index %@",[notesArray objectAtIndex:indexPath.row]);
cell.rightUtilityButtons = rightUtilityButtons;
cell.delegate=self;
return cell;
}
}
//cell.rightUtilityButtons = rightUtilityButtons;
return nil;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView==self.NotesandRemainderTable) {
if (section==0) {
return 1;
}
else if (section==1) {
if (leanerNots==nil || [leanerNots isEqual:[NSNull null]]) {
return 0;
}
else{
return [_notesArray count];
}
}
}else{
return 3;
}
return 0;
}
//这是我的剩余按钮代码......
-(IBAction)addRemainderAction:(id)sender{
self.lineLabel.hidden=NO;
self.remainderTableView.hidden=NO;
self.addButtonObj.hidden=NO;
//self.remainderTableView.frame=CGRectMake(0, 62, 300, 321);
//[self.view addSubview:self.remainderTableView];
self.NotesandRemainderTable.hidden=YES;
self.notesBtnObj.hidden=YES;
self.remainderBtnObj.hidden=YES;
_SubjectLabel.hidden=YES;
}
有没有人能帮我解决这个bug……我是Xcode新手
发布于 2014-10-29 13:46:46
您是否设置了第二个表视图的数据源和委托?
例如在viewDidLoad中:
self.remainderTableView.datasource = self;
self.remainderTableView.delegate = self;
并且您可能希望在显示表视图之前重新加载它们。为此,请为您的第二个表视图使用以下代码
[self.remainderTableView reloadData];
发布于 2014-10-29 14:26:39
从这段代码中不能完全清楚您是否正确地为两个UITableView
实例设置了delegate
和dataSource
。如果没有,那么这些委托方法将永远不会被调用。
无论如何,使用两个数据集而不是两个tableViews可能会更好地处理这种情况。像现在一样实现cellForRowAtIndexPath
,只是使用UIButton
的值,而不是根据tableView
的值有条件地创建单元格。当UITableViewDelegate
和UITableViewDataSource
方法已经允许您轻松地从不同的数据集获取数据时,两个UITableViews
对于这种情况似乎有点过分了。
https://stackoverflow.com/questions/26631847
复制相似问题