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:
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 doesnt have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that arent 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
Last edited by a moderator: