Wednesday, June 19, 2013

NSIndexPath initWithIndex example in Objective C (iOS).


NSIndexPath initWithIndex

Initializes an allocated NSIndexPath object with a one-node index path.

- (id)initWithIndex:(NSUInteger)index

Parameters
index
Index of the item in node 0 to point to.

Return Value of [NSIndexPath initWithIndex]
Initialized NSIndexPath object representing a one-node index path with index.

NSIndexPath initWithIndex example.
Use as below and also Don't forget to release myIndexPath object after using.

NSIndexPath *myIndexPath = [[NSIndexPath alloc] initWithIndex:[myIntObj intValue]];

Example of [NSIndexPath initWithIndex].
- (void)reloadTableView
{
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"aaa"];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"name" object:nil];
    NSLog(@"removeobserver");
    loadImageFinished = YES;
    // if your table has several sections you'll need to adopt the section number
    NSIndexSet *indices = [[NSIndexSet alloc] initWithIndex:0];
    [self.tableView reloadSections:indices withRowAnimation:UITableViewRowAnimationFade];
    [indices release];
}

NSIndexPath initWithIndex example.
- (void) allServersFound {
// called when bonjourservices has listings of machines:
bonjourMachines = [bonjourService foundServers] // NSArray of server names;
[machineListings reloadSections:[[[NSIndexSet alloc] initWithIndex:1] autorelease] withRowAnimation:UITableViewRowAnimationNone];
}

End of NSIndexPath initWithIndex example article.