Alright so the thing is that i want to display a website title in a tableview cell but it doesnt seem to work properly.
im using this to get it.
Code:
#pragma mark -
#pragma mark View lifecycle
- (void)viewDidLoad {
[super viewDidLoad];
webView1 = [[UIWebView alloc] init];
}
#pragma mark
#pragma mark Table view data source
// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 20;
}
// 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] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = [NSString stringWithFormat:@"%i", indexPath.row];
NSString *number;
if (indexPath.row < 10) {
number = [NSString stringWithFormat:@"000%i", indexPath.row];
}
else if (indexPath.row < 100) {
number = [NSString stringWithFormat:@"00%i", indexPath.row];
}
else if (indexPath.row < 1000) {
number = [NSString stringWithFormat:@"0%i", indexPath.row];
}
else {
number = [NSString stringWithFormat:@"%i", indexPath.row];
}
NSString *urls = [NSURL URLWithString:[NSString stringWithFormat:@"http://live.nhl.com/ice/realtime.htm?id=201002%@", number]];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:(NSURL *)urls];
[webView1 loadRequest:requestObj];
NSString *mySTR;
mySTR = [webView1 stringByEvaluatingJavaScriptFromString:@"document.title"];
cell.detailTextLabel.text = mySTR;
// Configure the cell.
return cell;
but what happens is that it only displays the last title because finding the title dosent happen instantly when the page is loaded. ive tried to using loops in the viewDidLoad method to try to get each to display but without success. Ive tried everything from making the app sleep to creating multiple functions to make the titles display properly.
If anyone knows how to make this work it would be great help since it would save me loads of time.
thanks