Welcome to my iphone development code blog

Welcome to my iphone development code blog
"SIMPLICITY IS BEST PROFESSION"

Thursday, July 15, 2010

how to load uitableview in background

make a method like below

- (void) loadData {
self.navigationItem.rightBarButtonItem = nil;
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];

[activityIndicator startAnimating];

UIBarButtonItem *activityItem = [[UIBarButtonItem alloc] initWithCustomView:activityIndicator];

[activityIndicator release];

self.navigationItem.rightBarButtonItem = activityItem;

[activityItem release];



NSOperationQueue *queue = [NSOperationQueue new];

NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(Loadtabledata)
object:nil];

[queue addOperation:operation];
[operation release];
}

and now make main method

-(void) Loadtabledata
{
searching = NO;
letUserSelectRow = YES;
//listOfItems2 = [listOfItems mutableCopy];
[listOfItems2 removeAllObjects];
DataController *controller = [[DataController alloc] init];
self.dataController = controller;
[self.dataController SetFilter:searchfilter];
[controller release];

searchbar.autocorrectionType = UITextAutocorrectionTypeNo;
usernames = [self.dataController GetList];
NSMutableArray *IDs = [NSMutableArray array];
IDs = [self.dataController GetIds];

NSEnumerator *userIterator= [usernames objectEnumerator];
NSString *username;
NSMutableArray *array = [NSMutableArray array];
while(username = [userIterator nextObject])
{
[array addObject:username];
}
NSEnumerator *idIterator= [IDs objectEnumerator];
NSMutableArray *arrayid = [NSMutableArray array];
while(IDs = [idIterator nextObject])
{
[arrayid addObject:IDs];
}

final = [[NSMutableDictionary alloc] initWithObjects:arrayid forKeys:array];

[array sortUsingSelector:@selector(compare:)];


NSArray *charArray = [[NSArray alloc] initWithObjects: @"a", @"b", @"c", @"d",
@"e", @"f", @"g", @"h", @"i", @"j", @"k", @"l", @"m", @"n",
@"o", @"p", @"q", @"r", @"s", @"t", @"u", @"v", @"w",
@"x", @"y", @"z", nil];

for (int a = 0; a < 26; a++)
{
NSMutableArray *array2 = [NSMutableArray arrayWithArray:usernames];
NSString *tmpValue = nil;
tmpValue =[charArray objectAtIndex: a];
NSPredicate *gpredicate = [NSPredicate predicateWithFormat:@"SELF beginswith %@ || SELF beginswith %@ ",tmpValue,[tmpValue uppercaseString]];
[array2 filterUsingPredicate:gpredicate];
NSDictionary *tempdict = [NSDictionary dictionaryWithObject:array2 forKey:@"Country"];
[listOfItems2 addObject:tempdict];
}
NSMutableArray *array2 = [NSMutableArray arrayWithArray:array];
NSPredicate *gpredicate = [NSPredicate predicateWithFormat:@"!SELF MATCHES %@",@"([a-zA-Z]).*"];
[array2 filterUsingPredicate:gpredicate];
NSDictionary *tempdict = [NSDictionary dictionaryWithObject:array2 forKey:@"Country"];
[listOfItems2 addObject:tempdict];

NSMutableArray *subgroupnames = [[NSMutableArray alloc]init];
subgroupnames = [self.dataController Getsgns];

NSEnumerator *sgnIterator= [subgroupnames objectEnumerator];
NSMutableArray *arraysgn = [NSMutableArray array];
while(subgroupnames = [sgnIterator nextObject])
{
[arraysgn addObject:subgroupnames];
}
finalsgn = [[NSMutableDictionary alloc] initWithObjects:arraysgn forKeys:arrayid];

NSMutableArray *mobs = [[NSMutableArray alloc]init];
mobs = [self.dataController Getmobiles];

NSEnumerator *mobIterator= [mobs objectEnumerator];
NSMutableArray *arraymob = [NSMutableArray array];
while(mobs = [mobIterator nextObject])
{
[arraymob addObject:mobs];
}

mobilnos = [[NSMutableDictionary alloc] initWithObjects:arraymob forKeys:arrayid];

NSMutableArray *ems = [[NSMutableArray alloc]init];
ems = [self.dataController GetEmails];

NSEnumerator *emsIterator= [ems objectEnumerator];
NSMutableArray *arrayem = [NSMutableArray array];
while(ems = [emsIterator nextObject])
{
[arrayem addObject:ems];
}

emails = [[NSMutableDictionary alloc] initWithObjects:arrayem forKeys:arrayid];

NSMutableArray *fes = [[NSMutableArray alloc]init];
fes = [self.dataController GetFexs];

NSEnumerator *fesIterator= [fes objectEnumerator];
NSMutableArray *arrayfe = [NSMutableArray array];
while(fes = [fesIterator nextObject])
{
[arrayfe addObject:fes];
}

fexs = [[NSMutableDictionary alloc] initWithObjects:arrayfe forKeys:arrayid];

NSMutableArray *bds = [[NSMutableArray alloc]init];
bds = [self.dataController GetBirthdays];

NSEnumerator *bdsIterator= [bds objectEnumerator];
NSMutableArray *arraybd = [NSMutableArray array];
while(bds = [bdsIterator nextObject])
{
[arraybd addObject:bds];
}

birthdays = [[NSMutableDictionary alloc] initWithObjects:arraybd forKeys:arrayid];

NSMutableArray *ans = [[NSMutableArray alloc]init];
ans = [self.dataController GetAnniversarydays];

NSEnumerator *ansIterator= [ans objectEnumerator];
NSMutableArray *arrayan = [NSMutableArray array];
while(ans = [ansIterator nextObject])
{
[arrayan addObject:ans];
}

annidays = [[NSMutableDictionary alloc] initWithObjects:arrayan forKeys:arrayid];

if([listOfItems isEqualToArray:listOfItems2 ])
{
}
else {
listOfItems = [listOfItems2 copy];
finaltmp = [final copy];
[self.tableview performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES];


}

[self writeToPlist];

self.navigationItem.rightBarButtonItem = nil;
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Refresh" style:UIBarButtonSystemItemDone target:self action:@selector(loadData)] autorelease];

}

No comments:

Post a Comment