Error when populate data

Discussion in 'iOS Programming' started by abraytee, Feb 10, 2011.

  1. abraytee, Feb 10, 2011
    Last edited by a moderator: Feb 10, 2011

    abraytee macrumors newbie

    Joined:
    Feb 8, 2011
    #1
    Hi,
    I start the application it populate my data in tableview , however when
    I'm trying to reload the data in UITableView after it clicks on button it exits the application, any help please

    This is my code in ViewController.m:


    Code:
    #import "kiksyloginViewController.h"
    
    @implementation kiksyloginViewController
    
    
    @synthesize usernameField;
    @synthesize passwordField;
    @synthesize loginButton;
    
    @synthesize listOfItems;
    
    
    
    - (IBAction) login: (id) sender
    
    
    {
        
    	NSString *post =[NSString stringWithFormat:@"username=%@&password=%@",usernameField.text, passwordField.text];
        
        NSString *hostStr = @"MY URL/iphonelogin-do.php?";
        
    	//hostStr = [hostStr stringByAppendingString:post];
        NSData *dataURL =  [NSData dataWithContentsOfURL: [ NSURL URLWithString: hostStr ]];    
        NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding];
    	
        NSLog(serverOutput);
    	
    	NSString *delimiter=@",";
    		NSArray *arr1=[serverOutput componentsSeparatedByString:delimiter];
    	
    	for(int i = 0; i < [listOfItems count]; i++) {
    		[[listOfItems objectAtIndex:i] release];
    	}
    	[listOfItems removeAllObjects];
    	NSString *fileName;
    	for(int i = 0; i <= 5; i++) {
    		fileName = [NSString stringWithFormat:@"myOtherImage_%d.png", i];
    		[listOfItems addObject:[UIImage imageNamed:fileName]];
    	}
    	//listOfItems=arr1;
    	[tblSimpleTable reloadData];
        
    	
    }
    
    - (void)didReceiveMemoryWarning {
        // Releases the view if it doesn’t have a superview.
        [super didReceiveMemoryWarning];
        
        // Release any cached data, images, etc that aren’t in use.
    }
    
    - (void)viewDidUnload {
        // Release any retained subviews of the main view.
        // e.g. self.myOutlet = nil;
    }
    
    
    - (void)dealloc {
        [super dealloc];
    }
    //RootViewController.m
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    	return [listOfItems count];
    }
    //RootViewController.m
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    	
    	
    	static NSString *CellIdentifier = @"Cell";
    	
    	UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    	if (cell == nil) {
    		cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    	}
    	
    	// Set up the cell...
    	NSString *cellValue = [listOfItems objectAtIndex:indexPath.row];
    	cell.text = cellValue;
    	
    	return cell;
    
    }
    - (void)viewDidLoad {
    	[super viewDidLoad];
    
    	//Initialize the array.
    	
    	//Add items
    	NSString *hostStr = @"MY URL/iphonelogin-do.php?";
        
    	//hostStr = [hostStr stringByAppendingString:post];
        NSData *dataURL =  [NSData dataWithContentsOfURL: [ NSURL URLWithString: hostStr ]];    
        NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding];
    //	serverOutput = [serverOutput stringByReplacingOccurrencesOfString:@"StockNumber" withString:@""];
       // NSLog(serverOutput);
    	NSString *delimiter=@",";
    		NSArray *arr=[serverOutput componentsSeparatedByString:delimiter];
    	listOfItems=arr;
    	
    	
    	
    	//Set the title
    	self.navigationItem.title = @"SERVER PARTS";
    }
    @end
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    1) Use the [ code ] [ /code ] tags. There is a sticky at the top of the forum telling you how

    2) Use the debugger. It will tell you which line the crash occurs on.
     
  3. abraytee thread starter macrumors newbie

    Joined:
    Feb 8, 2011
    #3
    Hi

    Thanks for your reply
    It doesn't show that it has any syntax error in the code but something wrong when it populates the data in table view.

    Any help in this sense!!!
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    Read 2) above. I am not suggesting there is a syntax error (that would be the compiler, not the debugger). The debugger will show you where the crash happens when the code is running. Usage of the debugger is a core skill that all programmers should have. I suggest you learn.
     

Share This Page