Obj-msg-send error in numberOfSectionsInTableView
Posted
by mukeshpawar
on Stack Overflow
See other posts from Stack Overflow
or by mukeshpawar
Published on 2010-03-24T09:52:49Z
Indexed on
2010/03/25
8:33 UTC
Read the original article
Hit count: 521
iphone-sdk
import "AddBillerCategoryViewController.h"
import "Globals.h"
import "AddBillerViewController.h"
import "AddBillerListViewController.h"
import"KlinnkAppDelegate.h"
@implementation AddBillerCategoryViewController
@synthesize REASON, RESPVAR, currentAttribute,tbldata,strOptions;
// This recipe adds a title for each section
//Initialize the table view controller with the grouped style
- (AddBillerCategoryViewController *) init
{
if (self = [super initWithStyle:UITableViewStyleGrouped]);// self.title = @"Crayon Colors";
return self;
}
-(void)showBack
{
[[self navigationController] pushViewController:[[AddBillerViewController alloc] init] animated:YES];
}
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if ([viewController isKindOfClass:[AddBillerCategoryViewController class]])
{
AddBillerCategoryViewController *controller = (AddBillerCategoryViewController *)viewController;
[controller.tbldata reloadData];
}
}
- (void)viewDidLoad
{
appDelegate = (KlinnkAppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.catListArray.count;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
//self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc]
// initWithTitle:@"Back"
// style:UIBarButtonItemStylePlain
// target:self
// action:@selector(showBack)] autorelease];
if(gotOK == 0)
{
//self.navigationItem.leftBarButtonItem.enabled = FALSE;
dt = [[DateTime alloc] init];
strChannelID = @"IGLOO|MOBILE";
strDateTime = [dt findDateTime];
strTemp = [dt findSessionTime];
strSessionID = [appDelegate.KMobile stringByAppendingString:strTemp];
strResponseURL = @"http://115.113.110.139/Test/CbbpServerRequestHandler";
strResponseVar = @"serverResponseXML";
strRequestType = @"GETCATEGORY";
NSLog(@"Current Session id - %@", strSessionID);
//conn = [[NSURLConnection alloc] init];
receivedData = [[NSMutableData data] retain]; //....................
currentAttribute = [[NSMutableString alloc] init];
// create XMl
xmlData = [[NSData alloc] init];
xmlData = [self createXML];
// XMl has been created now convert it in to string
xmlString = [[NSString alloc] initWithData:xmlData encoding:NSASCIIStringEncoding];
// Ataching other infromatin to he xml
parameterString = [[NSString alloc] initWithString:@"mobileRequestXML="];
requestString = [[NSString alloc] init];
requestString = [parameterString stringByAppendingString:xmlString];
// give space betn two element.
requestString = [requestString stringByReplacingOccurrencesOfString:@"><" withString:@"> <"];
// Initalizing other parameters
postData = [requestString dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
postLength = [NSString stringWithFormat:@"%d",[postData length]];
firstRequest = [[[NSMutableURLRequest alloc] init] autorelease];
REASON = [[NSMutableString alloc] init];
RESPVAR = [[NSMutableString alloc] init];
NSLog(@"\n \n Sending for 1st time........\n");
[self sendRequest];
NSLog(@"\n \n Sending for 2nd time........\n");
[self sendRequest];
NSLog(@"\n \n both request send........\n \n ");
}
//[tbldata reloadData];
[self retain];
[super viewDidLoad];
}
-(void)sendRequest
{
finished = FALSE;
NSLog(@"\n Sending Request \n\n %@", requestString);
conn = [[NSURLConnection alloc] init];
if(gotOK == 0)
[firstRequest setURL:[NSURL URLWithString:@"http://115.113.110.139/Test/CbbpMobileRequestHandler"]];
if(gotOK == 1)
{
[firstRequest setURL:[NSURL URLWithString:@"http://115.113.110.139//secure"]];
gotOK = 2;
}
[firstRequest setHTTPMethod:@"POST"];
[firstRequest setValue:postLength forHTTPHeaderField:@"Content-Length"];
[firstRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[firstRequest setHTTPBody:postData];
conn = [conn initWithRequest:firstRequest delegate:self startImmediately:YES];
[conn start];
while(!finished) {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
}
if (conn)
{
//receivedData = [[NSMutableData data] retain];
NSLog(@"\n\n Received %d bytes of data",[receivedData length]);
}
else
{
NSLog(@"\n Not responding");
}
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
NSLog(@" \n Send didReciveResponse");
[receivedData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
NSLog(@" \n Send didReciveData");
[receivedData appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
finished = TRUE;
NSLog(@" \n Send didFinishLaunching");
// do something with the data
// receivedData is declared as a method instance elsewhere
NSLog(@"\n\n Succeeded! DIDFINISH Received %d bytes of data\n\n ",[receivedData length]);
NSString *aStr = [[NSString alloc] initWithData:receivedData encoding:NSASCIIStringEncoding];
NSLog(aStr);
//[conn release];
if([aStr isEqualToString:@"OK"])
gotOK = 1;
NSLog(@" Value of gotOK - %d", gotOK);
if(gotOK == 2)
{
responseData = [aStr dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
parser = [[NSXMLParser alloc] initWithData:responseData];
[parser setDelegate:self];
NSLog(@"\n start parsing");
[parser parse];
NSLog(@"\n PArsing over");
NSLog(@"\n check U / S and the RESVAR is - %@",RESPVAR);
NSRange textRange;
textRange =[aStr rangeOfString:@"<"];
if(textRange.location != NSNotFound)
{
if([RESPVAR isEqualToString:@"U"])
{
self.navigationItem.rightBarButtonItem.enabled = TRUE;
self.navigationItem.leftBarButtonItem.enabled = TRUE;
NSLog(@" \n U.......");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:REASON delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
[alert release];
}
if([RESPVAR isEqualToString:@"S"])
{
NSLog(@"\n S........");
[[self navigationController] pushViewController:[[AddBillerCategoryViewController alloc] init] animated:YES];
//[self viewDidLoad];
//[tbldata reloadData];
}
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Connection Problem" message:@"Enable to process your request at this time. Please try again." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
[alert release];
//self.navigationItem.leftBarButtonItem.enabled = TRUE;
}
}
NSLog(@"\n Last line of connectionDidFinish ");
//[tableView reloadData];
}
-(NSData *)createXML
{
NSString *strXmlNode = @" channel alliaceid session reqtype responseurl responsevar ";
NSString *tempchannel = [strXmlNode stringByReplacingOccurrencesOfString:@"channel" withString:strChannelID options:NSBackwardsSearch range:NSMakeRange(0, [strXmlNode length])];
NSString *tempalliance = [tempchannel stringByReplacingOccurrencesOfString:@"alliaceid" withString:@"WALLET365" options:NSBackwardsSearch range:NSMakeRange(0, [tempchannel length])];
NSString *tempsession = [tempalliance stringByReplacingOccurrencesOfString:@"session" withString:strSessionID options:NSBackwardsSearch range:NSMakeRange(0, [tempalliance length])];
NSString *tempreqtype = [tempsession stringByReplacingOccurrencesOfString:@"reqtype" withString:strRequestType options:NSBackwardsSearch range:NSMakeRange(0,[tempsession length])];
NSString *tempresponseurl = [tempreqtype stringByReplacingOccurrencesOfString:@"responseurl" withString:strResponseURL options:NSBackwardsSearch range:NSMakeRange(0, [tempreqtype length])];
NSString *tempresponsevar = [tempresponseurl stringByReplacingOccurrencesOfString:@"responsevar" withString:strResponseVar options:NSBackwardsSearch range:NSMakeRange(0,[tempresponseurl length])];
NSData *data= [[NSString stringWithString:tempresponsevar] dataUsingEncoding:NSUTF8StringEncoding];
return data;
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if([elementName isEqualToString:@"RESPVAL"])
currentAttribute = [NSMutableString string];
if([elementName isEqualToString:@"REASON"])
currentAttribute = [NSMutableString string];
if([elementName isEqualToString:@"COUNT"])
currentAttribute = [NSMutableString string];
if([elementName isEqualToString:@"CATNAME"])
currentAttribute = [NSMutableString string];
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if([elementName isEqualToString:@"RESPVAL"])
{
[RESPVAR setString:currentAttribute];
//NSLog(@"\n Response VAR - %@", RESPVAR);
}
if([elementName isEqualToString:@"REASON"])
{
[REASON setString:currentAttribute];
//NSLog(@"\n Reason - %@", REASON);
}
if([elementName isEqualToString:@"COUNT"])
{
NSString *temp1 = [[NSString alloc] init];
temp1 = [temp1 stringByAppendingString:currentAttribute];
catCount = [temp1 intValue];
[temp1 release];
//NSLog(@"\n Cat Count - %d", catCount);
}
if([elementName isEqualToString:@"CATNAME"])
{
[appDelegate.catListArray addObject:[NSString stringWithFormat:currentAttribute]];
//NSLog(@"%@", appDelegate.catListArray);
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if(self.currentAttribute)
[self.currentAttribute setString:string];
}
/*
(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
*/
/*
(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
*/
/*
(void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
}
*/
/*
(void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
}
*/
/*
// Override to allow orientations other than the default portrait orientation.
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}
pragma mark Table view methods
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
// Customize the number of rows in the table view.
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
KlinnkAppDelegate *appDelegated = (KlinnkAppDelegate *)[[UIApplication sharedApplication] delegate];
return appDelegated.catListArray.count;
}
// Customize the appearance of table view cells.
(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...
AddBillerCategoryViewController *mbvc = (AddBillerCategoryViewController *)[appDelegate.catListArray objectAtIndex:indexPath.row];
[cell setText:mbvc.strOptions];
return cell;
}
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another view controller.
// AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherView" bundle:nil];
// [self.navigationController pushViewController:anotherViewController];
// [anotherViewController release];
gotOK = 0;
int j = indexPath.row;
appDelegate.catName = [[NSString alloc] init];
appDelegate.catName = [appDelegate.catName stringByAppendingString:[appDelegate.catListArray objectAtIndex:j]];
[[self navigationController] pushViewController:[[AddBillerListViewController alloc] init] animated:YES];
}
/*
// Override to support conditional editing of the table view.
(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
/*
// Override to support editing the table view.
(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/
/*
// Override to support conditional rearranging of the table view.
(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
- (void)dealloc {
[REASON release];
[RESPVAR release];
[currentAttribute release];
[tbldata release];
[super dealloc];
}
@end
In the Above code .. numberOfSectionsInTableView ,i get error of obj-msg-send i have intialize the array catlist and even not released it anywhere still why i am getting this error please help me i am badly stuck'
thanks in advacnce
© Stack Overflow or respective owner