سؤال

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.

هل كانت مفيدة؟

المحلول

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

نصائح أخرى

Your way of comparison is wrong .

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

All the best.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top