objective c 如何向扩展的 TableViewCell 添加内容
How to add Content to Expended TableViewCell in objective c
我是 Objective C 的新手,我无法将图像添加到扩展的 Table View Cell。
我的代码是:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if ([indexPath compare:self.expandedIndexPath] == NSOrderedSame) {
return 200.0; // Expanded height
}
return 63;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView beginUpdates]; // tell the table you're about to start making changes
if ([indexPath compare:self.expandedIndexPath] == NSOrderedSame) {
self.expandedIndexPath = nil;
} else {
self.expandedIndexPath = indexPath;
// hideview.hidden=NO;
}
[tableView endUpdates]; // tell the table you're done making your changes
}
我可以扩展单元格,但无法将图像添加到扩展的 table 视图单元格。
您也可以在 UIAlertController 中使用 UIAlertController 而不是 UITableView.Show UITableView。
听到的是如何在 UIAlertController 中显示 UITableView 的代码。
UIViewController *controller = [[UIViewController alloc]init];
CGRect rect;
if (idarray.count < 4) {
rect = CGRectMake(0, 0, 272, 160);
[controller setPreferredContentSize:rect.size];
}
else if (idarray.count < 6){
rect = CGRectMake(0, 0, 272, 300);
[controller setPreferredContentSize:rect.size];
}
else if (idarray.count < 8){
rect = CGRectMake(0, 0, 272, 200);
[controller setPreferredContentSize:rect.size];
}
else {
rect = CGRectMake(0, 0, 272, 250);
[controller setPreferredContentSize:rect.size];
}
alert =
[UIAlertController alertControllerWithTitle:@"Your Title"
message:@""
preferredStyle:UIAlertControllerStyleAlert];
TableName = [[UITableView alloc]initWithFrame:rect];
TableName.delegate = self;
TableName.dataSource = self;
[controller.view addSubview:TableName];
[controller.view bringSubviewToFront:TableName];
[controller.view setUserInteractionEnabled:YES];
[TableName setUserInteractionEnabled:YES];
[TableName setAllowsSelection:YES];
[alert setValue:controller forKey:@"contentViewController"];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}];
[alert addAction:cancelAction];
[self presentViewController:alert animated:YES completion:nil];
我是 Objective C 的新手,我无法将图像添加到扩展的 Table View Cell。 我的代码是:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if ([indexPath compare:self.expandedIndexPath] == NSOrderedSame) {
return 200.0; // Expanded height
}
return 63;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView beginUpdates]; // tell the table you're about to start making changes
if ([indexPath compare:self.expandedIndexPath] == NSOrderedSame) {
self.expandedIndexPath = nil;
} else {
self.expandedIndexPath = indexPath;
// hideview.hidden=NO;
}
[tableView endUpdates]; // tell the table you're done making your changes
}
我可以扩展单元格,但无法将图像添加到扩展的 table 视图单元格。
您也可以在 UIAlertController 中使用 UIAlertController 而不是 UITableView.Show UITableView。
听到的是如何在 UIAlertController 中显示 UITableView 的代码。
UIViewController *controller = [[UIViewController alloc]init];
CGRect rect;
if (idarray.count < 4) {
rect = CGRectMake(0, 0, 272, 160);
[controller setPreferredContentSize:rect.size];
}
else if (idarray.count < 6){
rect = CGRectMake(0, 0, 272, 300);
[controller setPreferredContentSize:rect.size];
}
else if (idarray.count < 8){
rect = CGRectMake(0, 0, 272, 200);
[controller setPreferredContentSize:rect.size];
}
else {
rect = CGRectMake(0, 0, 272, 250);
[controller setPreferredContentSize:rect.size];
}
alert =
[UIAlertController alertControllerWithTitle:@"Your Title"
message:@""
preferredStyle:UIAlertControllerStyleAlert];
TableName = [[UITableView alloc]initWithFrame:rect];
TableName.delegate = self;
TableName.dataSource = self;
[controller.view addSubview:TableName];
[controller.view bringSubviewToFront:TableName];
[controller.view setUserInteractionEnabled:YES];
[TableName setUserInteractionEnabled:YES];
[TableName setAllowsSelection:YES];
[alert setValue:controller forKey:@"contentViewController"];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}];
[alert addAction:cancelAction];
[self presentViewController:alert animated:YES completion:nil];