首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >如何通过按钮使用两个表视图

如何通过按钮使用两个表视图
EN

Stack Overflow用户
提问于 2014-10-29 21:38:04
回答 2查看 69关注 0票数 0

我想使用两个表视图,比如…。。

我正在使用popover控制器

第一个表视图在弹出控制器中,我有两个按钮(添加注释按钮和剩余按钮)当我单击剩余按钮时,我隐藏了第一个表视图并启用了第二个表视图

未调用cellforrowatindexpath的第二个表视图单元格的ut

仅用于它调用的第一个表视图,而不调用第二个表视图

这里我的代码是………。。

代码语言:javascript
代码运行次数:0
运行
复制
- (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;
}

//这是我的剩余按钮代码......

代码语言:javascript
代码运行次数: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新手

EN

回答 2

Stack Overflow用户

发布于 2014-10-29 21:46:46

您是否设置了第二个表视图的数据源和委托?

例如在viewDidLoad中:

代码语言:javascript
代码运行次数:0
运行
复制
self.remainderTableView.datasource = self;
self.remainderTableView.delegate = self;

并且您可能希望在显示表视图之前重新加载它们。为此,请为您的第二个表视图使用以下代码

代码语言:javascript
代码运行次数:0
运行
复制
[self.remainderTableView reloadData];
票数 0
EN

Stack Overflow用户

发布于 2014-10-29 22:26:39

从这段代码中不能完全清楚您是否正确地为两个UITableView实例设置了delegatedataSource。如果没有,那么这些委托方法将永远不会被调用。

无论如何,使用两个数据集而不是两个tableViews可能会更好地处理这种情况。像现在一样实现cellForRowAtIndexPath,只是使用UIButton的值,而不是根据tableView的值有条件地创建单元格。当UITableViewDelegateUITableViewDataSource方法已经允许您轻松地从不同的数据集获取数据时,两个UITableViews对于这种情况似乎有点过分了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26631847

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档