how to connect My table view to my webservice?
I would like to get the names of somes books in my webservice and set them in my tableView but I dont know how to get the data from my html and write them in my tableview. How can i do that? how can i read exactly parts of html and then write this parts in the cells of my tableView.
thanks!!
Now I´m writting in my tableView a local NSMutableArray but I would like to read from html and write them in my tableView. any idea?
- (void)viewDidLoad {
[super viewDidLoad];
listOfItems = [[NSMutableArray alloc] init];
NSArray *countriesToLiveInArray = [NSArray arrayWithObjects:@"Iceland", @"Greenland", @"Switzerland", @"Norway", @"New Zealand", @"Greece", @"Italy", @"Ireland", nil];
[listOfItems addObjectsFromArray:countriesToLiveInArray];
copyListOfItems = [[NSMutableArray alloc] init];
//Add the search bar
self.tableView.tableHeaderView = searchBar;
searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
searching = NO;
letUserSelectRo开发者_StackOverflow社区w = YES;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (searching)
return [copyListOfItems count];
else {
printf("ListaCountRow:%d\n", [listOfItems count]);
return [listOfItems count];
}
}
While you don't exactly "read HTML" for this kind of thing (i.e. reading in and then parsing HTML might not be as good as, say, making an API that returns XML or something similar that's more easily parsable), check out the ASIHTTPRequest library. They've got tons of example code on their site. Basically, you want to make an HTTP request to fetch the contents of a webpage. For instance www.mywebserver.com/mybooks.html or something similar. This will return data consisting of all the words and HTML markup found on that webpage. Then you can do whatever you want with it.
Make sense?
This problem requires more than a small post on Stack Exchange. I have written a 4 page tutorial on my blog about connecting to web services. Here is the link
It details both the iOS side of things AND the web side of things so you are not just trying to parse HTML but rather JSON or XML.
Good Luck!
精彩评论