Wednesday, 20 April 2016

Change dictionary value



NSDictionary  *tmpDict = [NSDictionary dictionaryWithObjectsAndKeys:
                                      // Object and key pairs
                                      @"2", @"userid",
                                      @"1", @"adminid",
                                      nil];

NSMutableDictionary *mutableDict = [tmpDict mutableCopy];
 [mutableDict setObject:@"2" forKey:@"adminid"];

  tmpDict = [mutableDict mutableCopy];

Newly add one key in NSDictionary:

NSMutableDictionary *mutableDict = [tmpDict mutableCopy];
 [mutableDict setObject:@"1" forKey:@"extra"];

  tmpDict = [mutableDict mutableCopy];

Wednesday, 13 April 2016

remove more than one object in array


NSMutableIndexSet *indexesToDelete = [NSMutableIndexSet indexSet];
        NSArray *deassMatches = [pickerArray valueForKey:eventstr.task_picker_id_str];
        for (int i =0; i<deassignArr.count; i++) {
            if ([deassMatches containsObject:[deassignArr objectAtIndex:i]])
            {
                NSUInteger indexvalue = [deassMatches indexOfObject:[deassignArr objectAtIndex:i]];
                [indexesToDelete addIndex:indexvalue];
            }
        }


        [pickerArray removeObjectsAtIndexes:indexesToDelete];


OR


NSMutableIndexSet *indexesToDelete = [NSMutableIndexSet indexSet];
NSUInteger currentIndex = 0;

for (id obj in yourArray) {
    //do stuff with obj
    if (shouldBeDeleted(obj)) {
        [indexesToDelete addIndex:currentIndex];
    }
    currentIndex++;
}

[yourArray removeObjectsAtIndexes:indexesToDelete];

Get particular index value from NSMutableArray


NSArray *matches = [disObjectArray valueForKey: @"userjid"];
        if ([matches containsObject:notification.object])
        {
            NSUInteger index = [matches indexOfObject:notification.object];
            NSArray *indexPathArray = [NSArray arrayWithObject:[NSIndexPath indexPathForRow:index inSection:0]];
            [friendslistTable reloadRowsAtIndexPaths:indexPathArray withRowAnimation:UITableViewRowAnimationNone];


        }

Call viewcontroller from Appdelegate or UIView

- (UIViewController *)visibleViewController:(UIViewController *)rootViewController
{
    if (rootViewController.presentedViewController == nil)
    {
        return rootViewController;
    }
    if ([rootViewController.presentedViewController isKindOfClass:[UINavigationController class]])
    {

        UINavigationController *navigationController = (UINavigationController *)rootViewController.presentedViewController;
        UIViewController *lastViewController = [[navigationController viewControllers] lastObject];
        
        return [self visibleViewController:lastViewController];
    }
    if ([rootViewController.presentedViewController isKindOfClass:[UITabBarController class]])
    {

        UITabBarController *tabBarController = (UITabBarController *)rootViewController.presentedViewController;
        UIViewController *selectedViewController = tabBarController.selectedViewController;
        
        return [self visibleViewController:selectedViewController];
    }

    UIViewController *presentedViewController = (UIViewController *)rootViewController.presentedViewController;
    
    return [self visibleViewController:presentedViewController];

}

// Call viewcontroller

       UIViewController *vc = [self visibleViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
        
        NextViewController *next = [[NextViewController alloc]initWithNibName:@"NextViewController" bundle:nil];
        [vc presentViewController:next animated:YES completion:nil];