2012-04-19 73 views
1

我想在我的scrollview中添加4个UITableViews,并用一些不同的数组弹出它们(让我们说我每个都有一个数组)。我已经将这个滚动视图添加到我的self.view(我在UIViewController类上做这个东西)。我怎样才能填充我的桌面视图任何人都可以帮忙吗?如何从UIViewController填充表格

一些细节:

这里是一个屏幕截图; enter image description here

这里是我的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; 

} 
+1

您没有在界面中输入数据源,您还必须实现该方法: - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; – WhiteTiger 2012-04-19 11:59:16

回答

1

老兄,你首先会令所有4代表的UIViewController中去委托和数据源,之后你会分配一个不同的标签为每个表..然后你将添加委托和数据源协议...并且您将像普通的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; 

这样你就会用同样的方法去做所有的表格视图..

+0

但是如何实现 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection :(NSInteger)部分 { }它不接受switch() - case .. – ilhnctn 2012-04-19 12:13:10

+0

再次测试表视图,如果需要再次使用if .. – 2012-04-19 12:15:16

+0

我解决了这个问题,它已经很多(我用你说的标签) – ilhnctn 2012-04-25 10:42:57