这个问题很简单,我现在用到了,声明两个tableview,给每个tableview设定tag,假定为1,2,然后在deleget 和Datesoure里边进行初始化得时候对tag进行判断,然后就可以进行相应得操作了,希望可以帮到楼主。
实例:
tableveiwA tag=0;
tableveiwB tag =1;
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
if (tableView.tag == 0) {
return 1;
}
else {
return 1;
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (tableView.tag == 0) {
return 30;
}
else {
return 10;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (tableView.tag == 0) {
return 150;
}
else {
return 50;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(tableView.tag == 0){
static NSString *Randoms = @"Random";
//add cell
return cell;
}
else {
//add cell
return cell;
}
}
实例:
tableveiwA tag=0;
tableveiwB tag =1;
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
if (tableView.tag == 0) {
return 1;
}
else {
return 1;
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (tableView.tag == 0) {
return 30;
}
else {
return 10;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (tableView.tag == 0) {
return 150;
}
else {
return 50;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(tableView.tag == 0){
static NSString *Randoms = @"Random";
//add cell
return cell;
}
else {
//add cell
return cell;
}
}
本文介绍了一种在iOS应用中通过设置不同的Tag来区分和管理多个TableView的方法。具体实现包括根据不同TableView的Tag来返回不同数量的Section、Row,以及设置不同的Cell高度。
1158

被折叠的 条评论
为什么被折叠?



