从didselectrowatindexpath加载多个详细信息视图

时间:2010-12-16 05:49:14

标签: iphone objective-c didselectrowatindexpath

我有一个表视图,基本上只有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]; 
}}

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

谢谢!


[编辑]

嘿伙计们在相对较短的时间内感谢您的所有答案!真的很感激。

2 个答案:

答案 0 :(得分:1)

您需要将此代码更改为

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]; 
}}

答案 1 :(得分:1)

你的比较方式是错误的。

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

一切顺利。