如何加载uitableview的子类

发布于 2024-12-02 20:14:16 字数 11763 浏览 0 评论 0原文

在过去的几天里,我一直在尝试加载 uitableview 的子类,并且遇到了各种麻烦。主要的一点是视图在解析任何数据之前加载。但他们还有其他问题,但最重要的是我可能不知道如何做到这一点,我已经从 rss feeds 中进行了各种单视图 xml 解析作为我的数据源,但从未从父视图单元格选择中加载不同的数据源。无论如何,对我来说,这就是麻烦开始发生的地方。

所以我希望有人能帮助我朝着正确的方向了解如何最好地做到这一点。

这是迄今为止我的解决方案。

ParentView.m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.
    //--- Idendify selected indexPath (section/row)
    if (indexPath.section == 0) {
        //--- Get the subview ready for use
        SearchResultsViewController *searchResultsViewController = [[SearchResultsViewController alloc] initWithNibName:@"SearchResultsViewController" bundle:nil];
        // ...
        //--- Sets the back button for the new view that loads
        self.navigationItem.backBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Back" style: UIBarButtonItemStyleBordered target:nil action:nil] autorelease];
        // Pass the selected object to the new view controller.
        [self.navigationController pushViewController:searchResultsViewController animated:YES];

        switch (indexPath.row)
        {
                case 0: searchResultsViewController.title = @"Manufacture";
                [searchResultsViewController setRequestString:@"manufacture.php"]; //sets the request string in searchResultsViewController
                break;

                case 1: searchResultsViewController.title = @"Model";
                break;

                case 2: searchResultsViewController.title = @"Year";
                break;

                case 3: searchResultsViewController.title = @"Key type";
                break;
        }

        //--- Clean up subview
        [searchResultsViewController release];
    }
}

所以基本上我有这段代码在 if 语句内调用我的子表视图,然后在 if 语句行中设置标题和请求字符串。

SearchResultsViewController.m

#import "SearchResultsViewController.h"
#import "ASIFormDataRequest.h"


@implementation SearchResultsViewController

@synthesize itemString;
@synthesize myDataArray;

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

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

- (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.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;

}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (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];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return [myDataArray count];
    NSLog(@"number or rows first = %d", [myDataArray count]);
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

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

    // Configure the cell...

    return cell;
}

/*
// 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:UITableViewRowAnimationFade];
    }   
    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;
}
*/

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.
    /*
     <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
     [self.navigationController pushViewController:detailViewController animated:YES];
     [detailViewController release];
     */
}

- (IBAction)setRequestString:(NSString *)string
{
    //clear datat
    [myDataArray removeAllObjects];
    //set up address
    NSMutableString *databaseURL = [[NSMutableString alloc] initWithString:@"http://127.0.0.1:8888/CodeTest/"];
    [databaseURL appendString:string];
    //call delegates
    NSURL *url = [NSURL URLWithString:databaseURL]; //LIVE mode
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
    [request setDelegate:self];
    [request startAsynchronous];
}

- (void)requestFinished:(ASIHTTPRequest *)request
{     
    NSString *responseString = [request responseString]; //Pass request text from server over to NSString 
    NSData *capturedResponseData = [responseString dataUsingEncoding:NSUTF8StringEncoding]; 

    [self startTheParsingProcess:capturedResponseData];
}

- (void)requestFailed:(ASIHTTPRequest *)request
{
    NSError *error = [request error];
    NSLog(@"%@", error);
}

#pragma mark - Parsing lifecycle
//--- Start parsing process using NSXMLParser ---------------->>
- (void)startTheParsingProcess:(NSData *)parserData
{
    NSXMLParser *parser = [[NSXMLParser alloc] initWithData:parserData]; //incoming parserDatapassed to NSXMLParser delegate which starts parsing process 

    [parser setDelegate:self];
    [parser parse]; //Starts the event-driven parsing operation.
    [parser release];

}

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
    if ([elementName isEqual:@"item"]) {
        // NSLog(@"Found title!");
        itemString = [[NSMutableString alloc] init];
    }
}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
    [itemString appendString:string];
}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
    if ([elementName isEqual:@"item"]) {
        //NSLog(@"ended title: %@", itemString);
        [myDataArray addObject:itemString];

        //TODO: Test release on memory consumption etc
        [itemString release];
        itemString = nil;
    }
}
//--- Finish parsing process using NSXMLParser ---------------->>




@end

在这一部分中,我设置了连接方法 - (IBAction)setRequestString:(NSString *)string,它启动连接获取数据并将其触发到 ASIHTTPRequest requestFinished 方法,然后将获取的数据传递给NSXMLParser 代表...然而这就是一切都容易失败的地方。好吧,它显示正确,但如果我放入一些 NSLogs,它会显示一些奇怪的解析..

#pragma mark - Parsing lifecycle
//--- Start parsing process using NSXMLParser ---------------->>
- (void)startTheParsingProcess:(NSData *)parserData
{
    NSXMLParser *parser = [[NSXMLParser alloc] initWithData:parserData]; //incoming parserDatapassed to NSXMLParser delegate which starts parsing process 

    [parser setDelegate:self];
    [parser parse]; //Starts the event-driven parsing operation.
    [parser release];

}

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
    if ([elementName isEqual:@"item"]) {
        // NSLog(@"Found title!");
        itemString = [[NSMutableString alloc] init];
        NSLog(@"step 1 = %@", itemString);
    }
}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
    [itemString appendString:string];
     NSLog(@"step 2 = %@", itemString);
}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
    if ([elementName isEqual:@"item"]) {
        //NSLog(@"ended title: %@", itemString);
        [myDataArray addObject:itemString];
         NSLog(@"step 3 = %@", itemString);

        //TODO: Test release on memory consumption etc
        [itemString release];
        itemString = nil;
    }
}
//--- Finish parsing process using NSXMLParser ---------------->>

给出这个结果

2011-09-06 14:09:12.921 Code[12060:207] step 2 = (null)
2011-09-06 14:09:12.923 Code[12060:207] step 1 = 
2011-09-06 14:09:12.923 Code[12060:207] step 2 = Honda
2011-09-06 14:09:12.924 Code[12060:207] step 3 = Honda
2011-09-06 14:09:12.926 Code[12060:207] step 2 = (null)
2011-09-06 14:09:12.927 Code[12060:207] step 1 = 
2011-09-06 14:09:12.930 Code[12060:207] step 2 = Nissan
2011-09-06 14:09:12.932 Code[12060:207] step 3 = Nissan
2011-09-06 14:09:12.932 Code[12060:207] step 2 = (null)
2011-09-06 14:09:12.933 Code[12060:207] step 1 = 
2011-09-06 14:09:12.933 Code[12060:207] step 2 = Mitsubishi
2011-09-06 14:09:12.934 Code[12060:207] step 3 = Mitsubishi
2011-09-06 14:09:12.934 Code[12060:207] step 2 = (null)
2011-09-06 14:09:12.935 Code[12060:207] step 1 = 
2011-09-06 14:09:12.936 Code[12060:207] step 2 = Toyota
2011-09-06 14:09:12.937 Code[12060:207] step 3 = Toyota
2011-09-06 14:09:12.938 Code[12060:207] step 2 = (null)
2011-09-06 14:09:12.939 Code[12060:207] step 1 = 
2011-09-06 14:09:12.939 Code[12060:207] step 2 = Mazda
2011-09-06 14:09:12.940 Code[12060:207] step 3 = Mazda
2011-09-06 14:09:13.001 Code[12060:207] step 2 = (null)

,我只是在尝试解决这个问题时遇到了麻烦,因为我之前使用过 nsxmlpaser 委托,并且无法弄清楚为什么它会搞砸,所以如果我受伤的话这是我从父视图调用此表视图的方式吗?

完成所有这些并表示视图上没有加载任何表...事实上,当我通过程序进行调试时,在任何解析发生之前都会调用 tableview row 方法,并且我不知道如何让解析发生。在此之前,我的数组计数实际上会加载适当数量的行。

I have been working on trying to load a subclass of a uitableview for the last few days and have been having various troubles with it. the main one being that the view is loading before any of the data is parsed. but their have been other issues but most of all really is probably my lack of understanding of how to do this, I have done various single view xml parsing from rss feeds as my datasource but never loading different datasources from a parent views cell selection.. which is where the trouble starts to happen, for me anyway.

So I was hoping that someone could help me in the right direction on how best to do this..

Here is my solution so far.

ParentView.m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.
    //--- Idendify selected indexPath (section/row)
    if (indexPath.section == 0) {
        //--- Get the subview ready for use
        SearchResultsViewController *searchResultsViewController = [[SearchResultsViewController alloc] initWithNibName:@"SearchResultsViewController" bundle:nil];
        // ...
        //--- Sets the back button for the new view that loads
        self.navigationItem.backBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Back" style: UIBarButtonItemStyleBordered target:nil action:nil] autorelease];
        // Pass the selected object to the new view controller.
        [self.navigationController pushViewController:searchResultsViewController animated:YES];

        switch (indexPath.row)
        {
                case 0: searchResultsViewController.title = @"Manufacture";
                [searchResultsViewController setRequestString:@"manufacture.php"]; //sets the request string in searchResultsViewController
                break;

                case 1: searchResultsViewController.title = @"Model";
                break;

                case 2: searchResultsViewController.title = @"Year";
                break;

                case 3: searchResultsViewController.title = @"Key type";
                break;
        }

        //--- Clean up subview
        [searchResultsViewController release];
    }
}

So basicly I have this code calling my child tableview, inside the section if statment and then setting the title and the request string in the row if statment.

SearchResultsViewController.m

#import "SearchResultsViewController.h"
#import "ASIFormDataRequest.h"


@implementation SearchResultsViewController

@synthesize itemString;
@synthesize myDataArray;

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

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

- (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.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;

}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (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];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return [myDataArray count];
    NSLog(@"number or rows first = %d", [myDataArray count]);
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

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

    // Configure the cell...

    return cell;
}

/*
// 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:UITableViewRowAnimationFade];
    }   
    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;
}
*/

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.
    /*
     <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
     [self.navigationController pushViewController:detailViewController animated:YES];
     [detailViewController release];
     */
}

- (IBAction)setRequestString:(NSString *)string
{
    //clear datat
    [myDataArray removeAllObjects];
    //set up address
    NSMutableString *databaseURL = [[NSMutableString alloc] initWithString:@"http://127.0.0.1:8888/CodeTest/"];
    [databaseURL appendString:string];
    //call delegates
    NSURL *url = [NSURL URLWithString:databaseURL]; //LIVE mode
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
    [request setDelegate:self];
    [request startAsynchronous];
}

- (void)requestFinished:(ASIHTTPRequest *)request
{     
    NSString *responseString = [request responseString]; //Pass request text from server over to NSString 
    NSData *capturedResponseData = [responseString dataUsingEncoding:NSUTF8StringEncoding]; 

    [self startTheParsingProcess:capturedResponseData];
}

- (void)requestFailed:(ASIHTTPRequest *)request
{
    NSError *error = [request error];
    NSLog(@"%@", error);
}

#pragma mark - Parsing lifecycle
//--- Start parsing process using NSXMLParser ---------------->>
- (void)startTheParsingProcess:(NSData *)parserData
{
    NSXMLParser *parser = [[NSXMLParser alloc] initWithData:parserData]; //incoming parserDatapassed to NSXMLParser delegate which starts parsing process 

    [parser setDelegate:self];
    [parser parse]; //Starts the event-driven parsing operation.
    [parser release];

}

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
    if ([elementName isEqual:@"item"]) {
        // NSLog(@"Found title!");
        itemString = [[NSMutableString alloc] init];
    }
}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
    [itemString appendString:string];
}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
    if ([elementName isEqual:@"item"]) {
        //NSLog(@"ended title: %@", itemString);
        [myDataArray addObject:itemString];

        //TODO: Test release on memory consumption etc
        [itemString release];
        itemString = nil;
    }
}
//--- Finish parsing process using NSXMLParser ---------------->>




@end

inside this part I have set up the connection method - (IBAction)setRequestString:(NSString *)string which starts up the the connection gets the data and fires it off to the ASIHTTPRequest requestFinished method which then passes the acquiered data off to the NSXMLParser delegates... however this is where it all tends to fall over. well it displays properly but if i put in some NSLogs it showing some weird parsing..

#pragma mark - Parsing lifecycle
//--- Start parsing process using NSXMLParser ---------------->>
- (void)startTheParsingProcess:(NSData *)parserData
{
    NSXMLParser *parser = [[NSXMLParser alloc] initWithData:parserData]; //incoming parserDatapassed to NSXMLParser delegate which starts parsing process 

    [parser setDelegate:self];
    [parser parse]; //Starts the event-driven parsing operation.
    [parser release];

}

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
    if ([elementName isEqual:@"item"]) {
        // NSLog(@"Found title!");
        itemString = [[NSMutableString alloc] init];
        NSLog(@"step 1 = %@", itemString);
    }
}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
    [itemString appendString:string];
     NSLog(@"step 2 = %@", itemString);
}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
    if ([elementName isEqual:@"item"]) {
        //NSLog(@"ended title: %@", itemString);
        [myDataArray addObject:itemString];
         NSLog(@"step 3 = %@", itemString);

        //TODO: Test release on memory consumption etc
        [itemString release];
        itemString = nil;
    }
}
//--- Finish parsing process using NSXMLParser ---------------->>

gives this result

2011-09-06 14:09:12.921 Code[12060:207] step 2 = (null)
2011-09-06 14:09:12.923 Code[12060:207] step 1 = 
2011-09-06 14:09:12.923 Code[12060:207] step 2 = Honda
2011-09-06 14:09:12.924 Code[12060:207] step 3 = Honda
2011-09-06 14:09:12.926 Code[12060:207] step 2 = (null)
2011-09-06 14:09:12.927 Code[12060:207] step 1 = 
2011-09-06 14:09:12.930 Code[12060:207] step 2 = Nissan
2011-09-06 14:09:12.932 Code[12060:207] step 3 = Nissan
2011-09-06 14:09:12.932 Code[12060:207] step 2 = (null)
2011-09-06 14:09:12.933 Code[12060:207] step 1 = 
2011-09-06 14:09:12.933 Code[12060:207] step 2 = Mitsubishi
2011-09-06 14:09:12.934 Code[12060:207] step 3 = Mitsubishi
2011-09-06 14:09:12.934 Code[12060:207] step 2 = (null)
2011-09-06 14:09:12.935 Code[12060:207] step 1 = 
2011-09-06 14:09:12.936 Code[12060:207] step 2 = Toyota
2011-09-06 14:09:12.937 Code[12060:207] step 3 = Toyota
2011-09-06 14:09:12.938 Code[12060:207] step 2 = (null)
2011-09-06 14:09:12.939 Code[12060:207] step 1 = 
2011-09-06 14:09:12.939 Code[12060:207] step 2 = Mazda
2011-09-06 14:09:12.940 Code[12060:207] step 3 = Mazda
2011-09-06 14:09:13.001 Code[12060:207] step 2 = (null)

Which I am just having trouble trying to work through because I have used nsxmlpaser delegates before and cannot figure out why its messed up so am woundering if it is the way I am calling this tableview from the parentview?

after all of this is done and said no tables are loaded on the view... infact when I debug through the program the tableview row method is called before any of the parsing happens and I cannot figure out how to get the parsing stuff to happen before that so my array count will actually load the appropriate amount of rows.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伊面 2024-12-09 20:14:16

我假设您的 setRequestString 操作附加到搜索按钮或类似的按钮 - 在将 SearchTableViewController 推到导航控制器上后按下该按钮?

如果是这样,则首次加载视图时将调用表视图委托方法,因此您需要在调用后

[parser parse]

通过调用

[self.tableView reloadData] 

来触发表视图单元格的重新加载来刷新表。

IE

- (void)startTheParsingProcess:(NSData *)parserData
{
    NSXMLParser *parser = [[NSXMLParser alloc] initWithData:parserData]; //incoming parserDatapassed to NSXMLParser delegate which starts parsing process 

    [parser setDelegate:self];
    [parser parse]; //Starts the event-driven parsing operation.
    [parser release];
    [self.tableView reloadData];

}

I'm assuming that your setRequestString action is attached to a search button or some such like - which is pressed after the SearchTableViewController has been pushed onto the navigation controller?

If so, the table view delegate methods are called when the view is first loaded, so you will need to refresh the table after your call to

[parser parse]

by putting a call to

[self.tableView reloadData] 

to trigger the reload of your table view cells.

i.e.

- (void)startTheParsingProcess:(NSData *)parserData
{
    NSXMLParser *parser = [[NSXMLParser alloc] initWithData:parserData]; //incoming parserDatapassed to NSXMLParser delegate which starts parsing process 

    [parser setDelegate:self];
    [parser parse]; //Starts the event-driven parsing operation.
    [parser release];
    [self.tableView reloadData];

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文