1

我想在我的滚动视图上添加 4 个 UITableView 并用一些不同的数组填充它们(假设我每个都有一个数组)。我也将此滚动视图添加到我的self.view(我在 UIViewController 类上执行此操作)。我如何填充我的 Tableviews 任何人都可以帮忙吗?

更多细节:

这是一个屏幕截图; 在此处输入图像描述

这是我的 UIViewControllerClass 的界面

#import <UIKit/UIKit.h>

@interface MainMenu : UIViewController<UITableViewDelegate>

@property (retain, nonatomic) IBOutlet UIScrollView *scrollView;
@property (retain, nonatomic) IBOutlet UITableView *group1;
@property (retain, nonatomic) IBOutlet UITableView *group2;
@property (retain, nonatomic) IBOutlet UITableView *group3;
@property (retain, nonatomic) IBOutlet UITableView *group4;

@end//i drag/dropped from IB, so there is no problem with synthesizes..

我想用不同的数组填充这些 tableview,如何处理这种情况..?非常感谢

附加说明;我尝试了这样的事情但没有效果:

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

    UITableViewCell *cell = [group1 dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    NSArray *array=[NSArray arrayWithObjects:@"one",@"two",@"tree", nil];
    cell.textLabel.text = [array objectAtIndex:indexPath.row];
    return cell;

}
4

1 回答 1

1

伙计,首先您将创建所有 4 个表的 uiviewcontroller de 委托和数据源,然后您将为每个表分配不同的标签..然后您将添加委托和数据源协议...您将实现数据源和委托方法就像普通的 uitableviewcontroller...所有这些方法都接收 Uitableview 参数,因此您将测试此表视图的标记,如:

...

if (tableView.tag == 10) {
//implement the table 1
NSArray *array=[NSArray arrayWithObjects:@"one",@"two",@"tree", nil];
cell.textLabel.text = [array objectAtIndex:indexPath.row];

} else if (tableView.tag == 20) {
//implement the table 2
} else if (tableView.tag == 30) {
//implement the table 3
} else if (tableView.tag == 40) {
//implement the table 4
}

return cell;

这样,您将使用相同的方法来执行所有表格视图..

于 2012-04-19T12:06:46.883 回答