在iphone中的Tableview重载问题?

时间:2011-12-07 07:00:54

标签: iphone objective-c xcode uitableview

这是我的代码我重新加载了tableview i; m得到exe错误的访问错误

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        NSLog(@"the count is %i",recievedSchool.count);
        return [recievedSchool count];
    }

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
       // recievedSchool=[[recievedSchool alloc]initWithArray:newschool copyItems:YES];
        static NSString *CellIdentifier = @"Cell";

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        }

       // NSLog(@"recieved school data are>>>>%@",newschool);
        cell.textLabel.text=[recievedSchool objectAtIndex:indexPath.row];

       // [newschool release];
        return cell;
    }





    -(void)searchRequest {


        NSString *post = 
        [[NSString alloc] initWithFormat:@"keyword=%@",searchBar.text];

        // NSString *urlString = [NSString stringWithFormat:@"http://3cs.co.in/mobileApps/home.php"];
        NSURL *url = [NSURL URLWithString:@"http://3cs.co.in/mobileApps/search.php"];

        NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60.0];
        NSString *msgLength = [NSString stringWithFormat:@"%d", [post length]];
        [theRequest setHTTPMethod:@"POST"];
        [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
        NSData * data=[post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
        [theRequest setHTTPBody: data];
        NSLog(@"the url is %@",url);
        NSLog(@"data is %@",data);
        conn= [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
        if( conn )
        {
            webData = [[NSMutableData data] retain];
        }
        else
        {
            NSLog(@"theConnection is NULL");
        }
        [post release];

    }




    -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
    {
        NSLog(@"did recieve response: %@", response);
        [webData setLength: 0];
    }
    -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
    {


        [webData appendData:data];
    }
    -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
    {

        [connection release];
        [webData release];
    }
    -(void)connectionDidFinishLoading:(NSURLConnection *)connection
    {
        NSMutableString *schoolStr = [[NSMutableString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
        NSLog(@"loginStatus  %@",schoolStr);
        recievedSchool= [NSMutableArray arrayWithArray:[schoolStr componentsSeparatedByCharactersInSet:
                         [NSCharacterSet characterSetWithCharactersInString:@"$"]]];
     //   [self getTeacher:schoolStr];
     //  [newschool addobject :schoolStr];

        [recievedSchool addObject:schoolStr];
        NSLog(@"array value is %@",recievedSchool);
        [self.tableView reloadData];

        [schoolStr release];
        [connection release];
        [webData release];


    }

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:3)

尝试

[recievedSchool retain];

以上

  

[self.tableView reloadData];

在connectionDidFinishLoading方法