1

因此,我正在对应用商店中的应用进行重要更新。我有一个带有标签栏和导航控制器的应用程序。当用户从列表中选择一个项目时,它会将它从我的服务器发送的 xml 文件中获取的链接发送到仅是 Web 视图的详细视图控制器。我遇到的问题是当用户返回到作为该选项卡的根视图的 tableview 时,详细视图没有被释放。当您在应用程序中选择其他选项时,详细视图不会更改。不是我的数据没有从 uishared 应用程序数据中释放,而是视图没有释放。我知道这里有很多类似的东西,我都试过了。我会给你一些我的代码,并非常感谢其他提示和技巧。我 15 岁,刚刚进入开发阶段,所以任何信息都有帮助。这是我认为任何人都需要帮助的代码。

表视图控制器

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
    NSString * storyLink = [[stories objectAtIndex: storyIndex] objectForKey: @"link"];

    // clean up the link - get rid of spaces, returns, and tabs...
    storyLink = [storyLink stringByReplacingOccurrencesOfString:@" " withString:@""];
    storyLink = [storyLink stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    storyLink = [storyLink stringByReplacingOccurrencesOfString:@"  " withString:@""];

    videoDetailViewController.title = @"Videos";

    ExampleAppDataObject* theDataObject = [self theAppDataObject];
    theDataObject.videoData = storyLink;

    if (self.videoDetailViewController == nil)
    {
        VideoDetailViewController *aBookDetail = [[[VideoDetailViewController alloc] initWithNibName:@"VideosDetailView" bundle:[NSBundle mainBundle]] autorelease];
        self.videoDetailViewController = aBookDetail;
        [aBookDetail release];
        aBookDetail = nil;
    }
    [self.navigationController pushViewController:videoDetailViewController animated:YES];
}

细节视图控制器:

#import "VideoDetailViewController.h"
#import "RSSEntry.h"
#import "ExampleAppDataObject.h"
#import "AppDelegateProtocol.h"

@implementation VideoDetailViewController

@synthesize activityIndicator;
@synthesize webView;
@synthesize pasteboard;

- (ExampleAppDataObject*) theAppDataObject;
{
    id<AppDelegateProtocol> theDelegate = (id<AppDelegateProtocol>) [UIApplication    sharedApplication].delegate;
    ExampleAppDataObject* theDataObject;
    theDataObject = (ExampleAppDataObject*) theDelegate.theAppDataObject;
    return theDataObject;
}

- (void)viewDidLoad
{    
    ExampleAppDataObject* theDataObject = [self theAppDataObject];
    NSString *urladdress = theDataObject.videoData;
    NSURL *url = [NSURL URLWithString:urladdress];
    NSURLRequest *requestobj = [NSURLRequest requestWithURL:url];

    [webView loadRequest:requestobj];
    pasteboard = [UIPasteboard generalPasteboard];
    [super viewDidLoad];
}

- (void)dealloc
{
    [webView release];
    webView = nil;

    [activityIndicator release];

    [pasteboard release];

    [VideoDetailViewController release];
    [urlData release];
    urlData = nil;

    [super dealloc];
}

@end

我跳过了很多我觉得不必要的代码。如果您想要实际文件,请发送电子邮件至 evan.stoddard@me.com

4

2 回答 2

2

不要在 detailViewController 页面中释放 webview,而是放入 [webView loadRequest:requestobj];viewDidAppear(),而不是 viewDidLoad

另外:使过渡更平滑的一种方法是:

if (self.videoDetailViewController == nil) {
    VideoDetailViewController *aBookDetail = [[[VideoDetailViewController alloc] initWithNibName:@"VideosDetailView" bundle:[NSBundle mainBundle]] autorelease];
    self.videoDetailViewController = aBookDetail;
    [aBookDetail release];
    aBookDetail = nil;

}

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

应该:

VideoDetailViewController *aBookDetail = [[VideoDetailViewController alloc]     initWithNibName:@"VideosDetailView" bundle:[NSBundle mainBundle]] ;
[self.navigationController pushViewController:videoDetailViewController animated:YES];
[aBookDetail release];
于 2012-06-11T01:02:09.973 回答
0

感谢 Anna Billstrom,我意识到我也应该使用viewDidAppear而不是viewDidLoad. 这是因为当从表视图中选择项目时,我通过外部数据类将数据传递给控制器​​。因此,详细视图控制器在从外部数据类加载数据之前加载。viewDidAppear 通过在选择单元格后视图加载并且外部类中有数据时获取数据来解决此问题。

于 2013-07-03T05:05:51.573 回答