从 didselectrowatindexpath 加载多个详细视图

发布于 2024-10-07 17:02:02 字数 986 浏览 1 评论 0原文

我有一个表视图,基本上只有 2 行,添加类别和删除类别。在选择添加类别时,我想加载添加类别视图,对于删除类别也类似。我该怎么做呢,因为 if 语句没有帮助。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *selectedCategory = [functionName objectAtIndex:[indexPath row]]; 
KeyCryptAppAppDelegate *appDelegate = (KeyCryptAppAppDelegate *)[[UIApplication sharedApplication] delegate];

if (selectedCategory = @"Add Category")
{

    addCategoryView = [[AddCategoryView alloc]initWithNibName:@"AddCategoryView" bundle:nil]; 
    [appDelegate.categoryNavController pushViewController:addCategoryView animated:YES];

}
if (selectedCategory = @"Delete Category")
{
    deleteCategoryView = [[DeleteCategoryView alloc]initWithNibName:@"DeleteCategoryView" bundle:nil]; 
    [appDelegate.categoryNavController pushViewController:deleteCategoryView animated:YES]; 
}}

此代码将使添加类别视图出现在两个详细视图中,而不是右侧的视图中。 请指教!

谢谢!


[编辑]

大家好,感谢您在相对较短的时间内提供的所有答案!真的很感激。

I have a table view, with just basically 2 rows, add category and delete category. On selection of lets say add category i want to load an add category view, and similar for the delete category. How would i go about doing this, cos an if statement doesn't help.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *selectedCategory = [functionName objectAtIndex:[indexPath row]]; 
KeyCryptAppAppDelegate *appDelegate = (KeyCryptAppAppDelegate *)[[UIApplication sharedApplication] delegate];

if (selectedCategory = @"Add Category")
{

    addCategoryView = [[AddCategoryView alloc]initWithNibName:@"AddCategoryView" bundle:nil]; 
    [appDelegate.categoryNavController pushViewController:addCategoryView animated:YES];

}
if (selectedCategory = @"Delete Category")
{
    deleteCategoryView = [[DeleteCategoryView alloc]initWithNibName:@"DeleteCategoryView" bundle:nil]; 
    [appDelegate.categoryNavController pushViewController:deleteCategoryView animated:YES]; 
}}

This code would make add category view appear in both detail views instead of the right one.
Please advise!

Thanks!


[EDIT]

Hey guys thanks for all your answers in a relatively short amount of time! Really appreciate it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

女中豪杰 2024-10-14 17:02:02

您需要将此代码更改为

if ([selectedCategory isEqualTo:@"Add Category"])
{

    addCategoryView = [[AddCategoryView alloc]initWithNibName:@"AddCategoryView" bundle:nil]; 
    [appDelegate.categoryNavController pushViewController:addCategoryView animated:YES];

}
else if([selectedCategory isEqualTo:@"Delete Category"])
{
    deleteCategoryView = [[DeleteCategoryView alloc]initWithNibName:@"DeleteCategoryView" bundle:nil]; 
    [appDelegate.categoryNavController pushViewController:deleteCategoryView animated:YES]; 
}}

You need to change this code to

if ([selectedCategory isEqualTo:@"Add Category"])
{

    addCategoryView = [[AddCategoryView alloc]initWithNibName:@"AddCategoryView" bundle:nil]; 
    [appDelegate.categoryNavController pushViewController:addCategoryView animated:YES];

}
else if([selectedCategory isEqualTo:@"Delete Category"])
{
    deleteCategoryView = [[DeleteCategoryView alloc]initWithNibName:@"DeleteCategoryView" bundle:nil]; 
    [appDelegate.categoryNavController pushViewController:deleteCategoryView animated:YES]; 
}}
柏林苍穹下 2024-10-14 17:02:02

你的比较方式是错误的。

if ([selectedCategory isEqualToString:@"Add Category"])

一切顺利。

Your way of comparison is wrong .

if ([selectedCategory isEqualToString:@"Add Category"])

All the best.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文