Objective c 我在单屏上使用了两个表视图,一个是平面,第二个是自定义单元格。只有一个在工作
我需要一个表视图用作下拉菜单,第二个表视图用于显示数据,即attendanceTBVW,它是customCell。从代码中可以看出,您只返回下拉菜单中的单元格。您不能返回attendanceTBVW的cell1。请返回两个表视图的单个单元格。希望对您有所帮助。您可以让它像为不同的tableview创建不同的单元格一样,并返回单独的单元格 因为两个表都不同,所以必须为这两个表返回不同的单元格 在您的代码中执行此操作Objective c 我在单屏上使用了两个表视图,一个是平面,第二个是自定义单元格。只有一个在工作,objective-c,uitableview,custom-cell,Objective C,Uitableview,Custom Cell,我需要一个表视图用作下拉菜单,第二个表视图用于显示数据,即attendanceTBVW,它是customCell。从代码中可以看出,您只返回下拉菜单中的单元格。您不能返回attendanceTBVW的cell1。请返回两个表视图的单个单元格。希望对您有所帮助。您可以让它像为不同的tableview创建不同的单元格一样,并返回单独的单元格 因为两个表都不同,所以必须为这两个表返回不同的单元格 在您的代码中执行此操作 NSString *cellIdentifier = @"cellID"; UI
NSString *cellIdentifier = @"cellID";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (tableView==self.monthTableVW)
{
if (cell == nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.textLabel.text=[self.monthArr objectAtIndex:indexPath.row];
cell.backgroundColor=[ UIColor colorWithRed:224.0f/255.0f green:188.0f/255.0f blue:113.0f/255.0f alpha:0.5f];
}
if (tableView==self.attendanceTBVW)
{
customeCell *cell1=[[customeCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier];
cell1=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell==nil)
{
NSArray *cellArr=[[NSBundle mainBundle]loadNibNamed:@"customeCell" owner:self options:nil];
cell=[cellArr objectAtIndex:0];
}
cell1.dateLbl.text=[self.monthArr objectAtIndex:indexPath.row];
}
return cell;
}
NSString *cellIdentifier = @"cellID1";
NSString *customCell = @"cellID2";
UITableViewCell *cell;
if (tableView==self.monthTableVW)
{
if (cell == nil)
{
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
//cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.textLabel.text=[self.monthArr objectAtIndex:indexPath.row];
cell.backgroundColor=[ UIColor colorWithRed:224.0f/255.0f green:188.0f/255.0f blue:113.0f/255.0f alpha:0.5f];
}
if (tableView==self.attendanceTBVW)
{
//customeCell *cell1=[[customeCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier];
//cell1=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell==nil)
{
(CustomTableViewCell *)cell = [tableView dequeueReusableCellWithIdentifier:customCell];
NSArray *cellArr=[[NSBundle mainBundle]loadNibNamed:@"customeCell" owner:self options:nil];
cell=[cellArr objectAtIndex:0];
cell.dateLbl.text=[self.monthArr objectAtIndex:indexPath.row];
}
//cell1.dateLbl.text=[self.monthArr objectAtIndex:indexPath.row];
}
return cell;
}
首先在序列图像板标识检查器中为不同的表视图单元格设置不同的单元格标识符。然后
if (tableView==self.monthTableVW) {
NSString *cellIdentifier = @"cellID";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.textLabel.text=[self.monthArr objectAtIndex:indexPath.row];
cell.backgroundColor=[ UIColor colorWithRed:224.0f/255.0f green:188.0f/255.0f blue:113.0f/255.0f alpha:0.5f];
return cell;
}
if (tableView==self.attendanceTBVW) {
NSString *cellIdentifier = @"customeCell";
customeCell *cell1=[[customeCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier];
cell1=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell==nil) {
NSArray *cellArr=[[NSBundle mainBundle]loadNibNamed:cellIdentifier owner:self options:nil];
cell=[cellArr objectAtIndex:0];
}
cell1.dateLbl.text=[self.monthArr objectAtIndex:indexPath.row];
return cell;
}
然后在此类中拖动dateLbl IBoutlet属性。然后在此类型中强制转换自定义单元格
#import CustomTableViewCell.h
试试看。希望它能起作用。尝试进行此更改。请检查它 这一个对我有用…非常感谢
我们必须在最后只返回一个表达式,我为这两个表达式尝试了一个通用表达式,但出现了异常错误显示错误,如“在UItableviewCell类型的对象上找不到属性dateLbl”您将dateLbl属性放在了哪里?经过一些小的更改,它对我起了作用,非常感谢..谢谢!
if (tableView==self.monthTableVW) {
NSString *cellIdentifier = @"cellID";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.textLabel.text=[self.monthArr objectAtIndex:indexPath.row];
cell.backgroundColor=[ UIColor colorWithRed:224.0f/255.0f green:188.0f/255.0f blue:113.0f/255.0f alpha:0.5f];
return cell;
}
if (tableView==self.attendanceTBVW) {
NSString *cellIdentifier = @"customeCell";
customeCell *cell1=[[customeCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier];
cell1=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell==nil) {
NSArray *cellArr=[[NSBundle mainBundle]loadNibNamed:cellIdentifier owner:self options:nil];
cell=[cellArr objectAtIndex:0];
}
cell1.dateLbl.text=[self.monthArr objectAtIndex:indexPath.row];
return cell;
}
UITableViewCell * raj=[[UITableViewCell alloc]init];
if (tableView==self.monthTableVW)
{
NSString *cellIdentifier = @"cellID";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.textLabel.text=[self.monthArr objectAtIndex:indexPath.row];
cell.backgroundColor=[ UIColor colorWithRed:224.0f/255.0f green:188.0f/255.0f blue:113.0f/255.0f alpha:0.5f];
raj= cell;
}
if (tableView==self.attendanceTBVW)
{
NSString *cellIdentifier = @"customeCell";
customeCell *cell1=[[customeCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier];
cell1=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell1==nil) {
NSArray *cellArr=[[NSBundle mainBundle]loadNibNamed:cellIdentifier owner:self options:nil];
cell1=[cellArr objectAtIndex:0];
}
cell1.dateLbl.text=[self.monthArr objectAtIndex:indexPath.row];
raj= cell1;
}
return raj;