您可以通過使用單個tableview來實現此目的。你需要做的是使用數據源和委託方法來區分Day和Month的數據。你能做什麼是使用枚舉表數據一鍵是日,第二是月。 現在在控制器的.h中
enum TableContentType {
kDay = 0,
kMonth = 1
};
@property (assign) enum TableContentType tableContentType;
@property (nonatomic, strong) NSMutableArray * monthDataArray;
@property (nonatomic, strong) NSMutableArray * dayDataArray;
現在在。M檔
的動作,從日表的內容切換到月或反之亦然
- (IBAction)changeTableContent:(id)sender
{
self.tableContentType = (self.tableContentType == kDay) ? kMonth : kDay;
[self.table reloadData];
}
在表的數據源和委託方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return (self.tableContentType == kDay) ? self.dayDataArray.count : self.monthDataArray.count ;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;
if (cell == nil) {
cell = (self.tableContentType == kDay) ? [self createDayCellForIndexPath: indexPath] : [self createMOnthCellForIndexPath: indexPath];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(self.tableContentType == kDay)
{
[self dayCellTappedForIndexPath: indexPath];
}else
{
[self monthCellTappedForIndexPath: indexPath];
}
}
方法爲白天鑑於indexpath創建細胞和月
- (UITableViewCell *)createDayCellForIndexPath:(NSIndexPath*)indexPath
{
UITableViewCell * dayCell = nil;
// write your code for day cell here
return dayCell;
}
- (UITableViewCell *)createMonthCellForIndexPath:(NSIndexPath*)indexPath
{
UITableViewCell * monthCell = nil;
// write your code for month cell here
return monthCell;
}
執行單元格選擇操作的方法日,月
- (void)dayCellTappedForIndexPath: (NSIndexPath *)indexPath
{
// write your code for day cell tap
}
- (void)monthCellTappedForIndexPath: (NSIndexPath *)indexPath
{
// write your code for month cell tap
}
這將有助於你奶源您有
@ user28882259參考我的答案的情況。肯定會幫助你。 – Smita