所以我正在对appstore上的应用程序进行重要更新。我有一个带标签栏和导航控制器的应用程序。当用户从列表中选择一个项目时,它会将从服务器发送的xml文件中获取的链接发送到仅作为Web视图的详细视图控制器。我遇到的问题是当用户返回到tableview时,该视图是该选项卡的根视图,不会释放详细信息视图。当您在应用程序中选择其他选项时,详细信息视图不会更改。并不是说我的数据没有从uishared应用程序数据中释放,而是它的视图没有发布。我知道这里有很多类似的东西,我已经尝试了所有这些。我会给你一些我的代码,并非常感谢其他提示和技巧。我15岁刚刚进入开发,所以任何信息都有帮助。下面是我认为对任何人都有帮助的代码。
TableViewController
- (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];
}
DetailViewController:
#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
答案 0 :(得分:2)
不要在detailViewController页面中释放webview,而是放置
viewDidAppear()中的[webView loadRequest:requestobj];
,而不是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];
答案 1 :(得分:0)
感谢Anna Billstrom,我意识到我也应该使用viewDidAppear
代替viewDidLoad
。这是因为当从表视图中选择项目时,我通过外部数据类将数据传递给控制器。因此,在从外部数据类加载数据之前,将加载详细视图控制器。 viewDidAppear通过在选择单元格并且外部类中有数据后加载视图时获取数据来解决此问题。