开发者

Life cycle of UIVIew controller+iphone

开发者 https://www.devze.com 2023-04-02 12:54 出处:网络
I want to clear about the life cycle of the UIVIEWCONTROLLER in iphone: - (void)viewDidLoad { [super viewDidLoad];

I want to clear about the life cycle of the UIVIEWCONTROLLER in iphone:

- (void)viewDidLoad {
       [super viewDidLoad];
    }

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{   
return 3;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 50.0;
}


//This is the method which will be called and IS REQ since we impl interface/delegate
- (UITableViewCell *)tableV开发者_运维百科iew:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//We use own own table cell now instead of default
UITableViewCell *cell   =   [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"XMl_CELL"];    
//Our cell has images and text
Wsp = [[WebServiceParser alloc]initWithURLMy:@"http://api.geonames.org/findN"];
return cell;
}

 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{ 

//MyParserData *data=(MyParserData*)[arrayTable objectAtIndex:indexPath.row];
//NSLog(@"Here->%@",data.url);
    [tableView deselectRowAtIndexPath:indexPath animated:TRUE];
}

Please explain to me which method will call first and why.

I want to call one method for web service parsing then according to its response i want to put the row count and changes in the table view.

i had tried to alloc on array in viewdidload method and set the row count according to the count of the array.But it is giving me bad_access.Becoz it is not allocing the proper count.

Please explain if any one had any idea.. Thanks in advance


This is explained well in the View Controller Programmers Guide for iOS


Why not put an NSLog in each method and run it to see the order?

Also, it looks like you are populating the cells/rows with a network call for each cell (and never releasing the allocs - you probably want to autorelease those) - so why do you need an array?


I hope my code would help you as I don't understand your question properly

- (void)viewDidLoad 
{
    myApp = (myAppDelegate *) [[UIApplication sharedApplication] delegate];

    [self performSelectorInBackground:@selector(startParsing) withObject:nil];
    [super viewDidLoad];

}

- (void) startParsing
{
    [self performSelectorOnMainThread:@selector(startIndicator) withObject:nil waitUntilDone:NO];

    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];   

    NSURL *url = [[NSURL alloc] initWithString:@"http://www.aaaa.org"];
    NSData *data = [NSData dataWithContentsOfURL:url];

    // 2 -- parsing
    parser = [[myParser alloc] init];

    [parser parseXML:data];
    [data release];
    [parser print];

    [self performSelectorOnMainThread:@selector(updateTable) withObject:nil waitUntilDone:NO];
    [pool release]; 

}

- (void) startIndicator
{
    av.hidesWhenStopped = YES;
    [av startAnimating];
}

- (void) updateTable
{
    [av stopAnimating];
    [myTable reloadData];

}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    int n = [myApp.myParsedDataArray count];
    return n ; 
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    int cellHeight = 70 ;
    return cellHeight; 
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
   // code
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
   //Code
}

I have used an array, that stores parsed data, in delegate file so that I can use it anywhere.

Hope it gives you an idea...

0

精彩评论

暂无评论...
验证码 换一张
取 消