views:

44

answers:

1

Hi everybody, I'm trying to add a UIWebView as a subview of a UITableViewCell in order to display some data formatted with MIMEType 'application/xhtml+xml'. Even just initializing the UIWebView as described in the following code leads the application to crash!

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {    
NSLog(@"cellForRowAtIndexPath: '%d' in section '%d'", indexPath.section, indexPath.row);

static NSString *CellIdentifier = @"Cell";

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

UIWebView * webView = [[UIWebView alloc]initWithFrame:cell.frame];

return cell;

}

I'm getting this message:

bool _WebTryThreadLock(bool), 0x10a7f50: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...<

I can not figure out where I'm doing wrong!

Thanks for help

Gerald

A: 

The error message tells you what's going on: You are probably not on the main thread? You should only access UIKit from the main thread.

Additionally, cell.frame is most likely not what you want here. Try to set a fixed size with CGRectMake(...). And don't forget to add it. :-)

Eiko
Wow! You saved my night!Only reading the message was not enough for me, you pushed me to look forward in my code. I was calling the reloadData method in a new thread, a.k.a not the main thread!Many thanks EikoGreetings from FranceGerald
Gerald
You're welcome. Been there, done that. Feel free to mark this answer as "accepted". :-)
Eiko