单个 ViewController 中的多个 UITableview [英] Multiple UITableview in Single Viewcontroller

查看:16
本文介绍了单个 ViewController 中的多个 UITableview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 viewcontroller,我想显示 3 个 tableviews(因为内容和表格属性不同).如何在一个 viewcontroller 中为 3 个表添加这些委托方法?

I have a viewcontroller in that i want to show 3 tableviews(because the content and the table properties are different). How do i add these delegate methodes for 3 tables in one viewcontroller?

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [array1 count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {}

编辑

那么,如果我想使用自定义 celluislider 添加到一个表格行,并且当我滑动该值时我想更改显示亮度,我该怎么办?

So what will i do if i want add a uislider to one table row using custom cell and when i slide the value i want to change the display brightness?

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    if (tableView == _displayThemes) {
        return 1;
    } else {
        return 1; 
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if(tableView==_displayThemes) {
        return 1;
    } else {
        return 5;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    if (tableView == _displayThemes) {
        cell.textLabel.text = [displaytheme objectAtIndex:indexPath.row];
        return cell;
    } else {
        cell.textLabel.text = [fontlist objectAtIndex:indexPath.row];
        return cell;
    }
}


- (IBAction)fontButton:(id)sender {
    _fontList = [[UITableView alloc]init];
    [self.view addSubview:_fontList];
    [UIView animateWithDuration:1.5
            delay:0
            options: UIViewAnimationOptionTransitionCurlUp
            animations:^{
                _fontList.fram e= CGRectMake(0,800,320,200);
            }
            completion:^(BOOL finished){
                _fontList.frame = CGRectMake(0,280,320,200);     
    }];

    [_fontList reloadData];
}

- (IBAction)button:(id)sender {
    _displayThemes = [[UITableView alloc]init];
    [self.view addSubview:_displayThemes];
    [UIView animateWithDuration:1.5
            delay:0
            options: UIViewAnimationOptionTransitionCurlUp
            animations:^{
                _displayThemes.frame=CGRectMake(0,800,320,200);
            }
            completion:^(BOOL finished){
                _displayThemes.frame=CGRectMake(0,280,320,200);
    }];
}

推荐答案

这和你用一个 table view 做的一样,但你应该检查当前正在使用哪个 tableview.

It will be the same as you do it with one table view, but you should check which tableview is currently using.

myTableView1.dataSource = self;
...

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  if (tableView == myTableView1) {
    // your code 1
  }
  else 
  if (tableView == myTableView2) {
      // your code 2
  }
  else 
  if (tableView == myTableView3) {
      // your code 3
  }
}

关于亮度:

如何在 iOS 5 应用中更改亮度?

关于 UISlider 它有 minimunValuemaximumValue 属性.

And about UISlider it has minimunValue and maximumValue properties.

- (void) sliderChanged:(UISlider*)sender{
    UISlider *slider = (UISlider*)sender;
    [[UIScreen mainScreen] setBrightness:slider.value];
}

slider.tag = 1;
[cell addSubview:slider];


...
// when you need..
indexPath = [NSIndexPath indexPathForRow:myRow inSection:mySecion];
UISlider* slider = (UISlider*) [[self.tableView cellForRowAtIndexPath:indexPath] viewWithTag:1];

这篇关于单个 ViewController 中的多个 UITableview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆