【发布时间】:2012-06-11 00:54:53
【问题描述】:
因此,我正在对我在应用商店中拥有的应用进行重要更新。我有一个带有标签栏和导航控制器的应用程序。当用户从列表中选择一个项目时,它将从我的服务器发送的 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];
}
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
【问题讨论】:
-
当你说“不释放”时,你怎么知道,你用什么来监控对象?另外,用户会看到什么?
-
好吧,在这种情况下有一个视频,当我返回堆栈的导航部分并选择任何其他 tableviewcell 并返回 detailview 时,它仍然是相同的视频在同一个位置暂停.
-
啊。媒体播放器。您可能想在“后退”功能上做一些事情来暂停/释放媒体播放器对象。在仍在运行的对象上接近它,本质上,而不是包含它的容器。
-
您可能想在这里提出一个新问题,并用 webview 标记它,而不是使用控制器的东西。你会得到更具体的答案(和专业知识)。为什么选择 webview 而不是 MP?
标签: iphone uinavigationcontroller uitabbarcontroller uitableview