1

我的表有问题,我使用 Apple 的 LazyTableImages 示例,然后再嵌入到我的项目中。像这样加载我的xml时一切正常

<im:title>1</im:title>
<content type="html">some desc</content>
<im:releaseDate label="October 23, 2013">2013-10-23T00:00:00-07:00</im:releaseDate>
<im:artist href="http:/facebook.com">Facebook</im:artist>               
<im:name>1</im:name>
<im:image height="53">http://chingfong.com/Icon.png</im:image>
<url>http://facebook.com/url>
<im:date>Ene, 27 2013</im:date>

这是我的 AppRecord.h

@property (nonatomic, strong) NSString *appName;
@property (nonatomic, strong) UIImage *appIcon;
@property (nonatomic, strong) NSString *artist;
@property (nonatomic, strong) NSString *imageURLString;
@property (nonatomic, strong) NSString *appURLString;
@property (nonatomic, strong) NSString *appURL;

ParseOperation.h - 我还添加了

static NSString *kUrlStr    = @"url";


 - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
                                          namespaceURI:(NSString *)namespaceURI
                                         qualifiedName:(NSString *)qName
    {
        if (self.workingEntry)
        {
            if (self.storingCharacterData)
            {
                NSString *trimmedString = [self.workingPropertyString stringByTrimmingCharactersInSet:
                                           [NSCharacterSet whitespaceAndNewlineCharacterSet]];
                [self.workingPropertyString setString:@""];  // clear the string for next time
                if ([elementName isEqualToString:kIDStr])
                {
                    self.workingEntry.appURLString = trimmedString;
                }
                else if ([elementName isEqualToString:kNameStr])
                {        
                    self.workingEntry.appName = trimmedString;
                }
                else if ([elementName isEqualToString:kImageStr])
                {
                    self.workingEntry.imageURLString = trimmedString;
                }
                else if ([elementName isEqualToString:kUrlStr])
                {
                    self.workingEntry.appURL = trimmedString;
                }
                else if ([elementName isEqualToString:kArtistStr])
                {
                    self.workingEntry.artist = trimmedString;
                }
            }
            else if ([elementName isEqualToString:kEntryStr])
            {
                [self.workingArray addObject:self.workingEntry];  
                self.workingEntry = nil;
            }
        }

    }

tableView 中的 RootViewController.m didSelectRowAtIndexPath

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    AppRecord *appRecord = [self.entries objectAtIndex:indexPath.row];
    NSString *urlAddress = appRecord.appURL;
    NSURL *url = [NSURL URLWithString:urlAddress];
    WebViewController *detailViewController = [[WebViewController alloc] initWithNibName:@"WebViewController" bundle:nil];
//    WebViewController.sites= [_entries objectAtIndex:indexPath.row];
    [detailViewController.webView loadRequest:[NSURLRequest requestWithURL:url]];

    [self.navigationController pushViewController:detailViewController animated:YES];
}

WebViewController.h

@interface WebViewController : UIViewController <UIWebViewDelegate>
@property (nonatomic, strong) IBOutlet UIWebView *webView;

表格加载正常,当我选择单元格时它推送到 WebViewController 但 UIWebView 没有加载网页,它只是空白(白色)。

谁能帮我修复它?非常感谢!

4

1 回答 1

0

我认为对您来说最好的方法是将 url 从RootViewControllerto传递WebViewController并在WebViewController. 所以你需要像这样修改你的代码:

tableView 中的 RootViewController.m didSelectRowAtIndexPath

// Add a @property of your detail view for lazing
@property (nonatomic, strong) WebViewController *detailViewController;

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    AppRecord *appRecord = [self.entries objectAtIndex:indexPath.row];

    if (!_detailViewController)
        self.detailViewController = [[WebViewController alloc] initWithNibName:@"WebViewController" bundle:nil];

   self.detailViewController.websiteURL = appRecord.appURL;

    [self.navigationController pushViewController:self.detailViewController animated:YES];

}

WebViewController.h

@interface WebViewController : UIViewController <UIWebViewDelegate>
@property (nonatomic, strong) IBOutlet UIWebView *webView;
@property (nonatomic, strong) NSString *websiteURL;

WebViewController.m

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    // URL Request Object
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:[NSURL URLWithString:_websiteURL]];

    // Load the request in the UIWebView
    [_webView loadRequest:requestObj];
}
于 2013-11-05T14:29:04.820 回答