Iphone 打开带有不带NavigationController的表的视图
我对使用Cocoa-Touch/XCode进行开发非常陌生,我遇到了一个问题 我正在为一个新闻网站制作一种RSS阅读器,我有5个表格视图,在TabBarController中有5个选项卡。如果有人选择了一个新闻项目,我希望打开另一个视图来显示完整的新闻项目。我的问题是它不起作用 这是我的代码:Iphone 打开带有不带NavigationController的表的视图,iphone,cocoa-touch,xcode,rss,uitabbarcontroller,Iphone,Cocoa Touch,Xcode,Rss,Uitabbarcontroller,我对使用Cocoa-Touch/XCode进行开发非常陌生,我遇到了一个问题 我正在为一个新闻网站制作一种RSS阅读器,我有5个表格视图,在TabBarController中有5个选项卡。如果有人选择了一个新闻项目,我希望打开另一个视图来显示完整的新闻项目。我的问题是它不起作用 这是我的代码: - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection(NSInteger)section{ return [[
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection(NSInteger)section{
return [[[self rssParser]rssItems]count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"rssItemCell"];
if(nil == cell){
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"rssItemCell"]autorelease];
}
cell.textLabel.text = [[[[self rssParser]rssItems]objectAtIndex:indexPath.row]title];
cell.detailTextLabel.text = [[[[self rssParser]rssItems]objectAtIndex:indexPath.row]description];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[[self appDelegate] setCurrentlySelectedBlogItem:[[[self rssParser]rssItems]objectAtIndex:indexPath.row]];
[self.appDelegate loadNewsDetails];
}
它在我的委托中调用此方法:
-(void)loadNewsDetails{
[[self rootController]pushViewController:detailController animated:YES];
}
请告诉我我做错了什么。顺便说一句,我不想使用NavigationController,只想使用我正在使用的选项卡栏
提前感谢,
肯有两点:
你为什么不想使用导航控制器呢?
pushViewController:animated:是UINavigationController的一种方法。如果未使用UINavigationController,则无法使用此方法获取滑动动画。此时,您唯一的其他实际选择是使用presentModalViewController:animated:,它将显示从底部向上滑动的模式视图。完成后,您需要提供一种方法来驳回它。
如果仍然需要滑动动画,但不需要UINavigationBar,则可以使用UINavigationController,但使用setNavigationBarHidden:animated:方法隐藏导航栏。在不知道最终结果是什么的情况下,很难说什么是正确的解决方案。我同意Alex的观点,如果可以的话,你应该尝试使用导航控制器,但是如果你不想,不用担心,你仍然可以得到非常类似的滑动动画。下面的代码将显示一个视图,该视图考虑了接口方向,并从右侧推动,而不管设备位置如何,隐藏方法也是如此
- (void) pushMyView:(UIInterfaceOrientation)interfaceOrientation {
[self.view addSubview:myNewView.view];
CATransition *animation = [CATransition animation];
[animation setDuration:0.3];
[animation setType:kCATransitionPush];
// Compute direction by orientation
if (UIInterfaceOrientationPortrait == interfaceOrientation) {
[animation setSubtype:kCATransitionFromRight];
} else if (UIInterfaceOrientationLandscapeLeft == interfaceOrientation) {
[animation setSubtype:kCATransitionFromBottom];
} else if (UIInterfaceOrientationLandscapeRight == interfaceOrientation) {
[animation setSubtype:kCATransitionFromTop];
} else if (UIInterfaceOrientationPortraitUpsideDown == interfaceOrientation) {
[animation setSubtype:kCATransitionFromLeft];
}
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[window layer] addAnimation:animation forKey:@"ShowMyNewView"];
}
-(void) hideMyView:(UIInterfaceOrientation)interfaceOrientation {
[myNewView.view removeFromSuperview];
CATransition *animation = [CATransition animation];
[animation setDuration:0.3];
[animation setType:kCATransitionPush];
// Compute direction by orientation
if (UIInterfaceOrientationPortrait == interfaceOrientation) {
[animation setSubtype:kCATransitionFromLeft];
} else if (UIInterfaceOrientationLandscapeLeft == interfaceOrientation) {
[animation setSubtype:kCATransitionFromTop];
} else if (UIInterfaceOrientationLandscapeRight == interfaceOrientation) {
[animation setSubtype:kCATransitionFromBottom];
} else if (UIInterfaceOrientationPortraitUpsideDown == interfaceOrientation) {
[animation setSubtype:kCATransitionFromRight];
}
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[window layer] addAnimation:animation forKey:@"HideMyNewView"];
}
使用选项卡栏控制器并不意味着不能同时使用一个或多个导航控制器。例如,iPod应用程序就是这样做的,这就是用户期望你的应用程序的行为方式 您只需将五个UINavigationController对象添加到MainWindow.xib文件中,每个选项卡下一个。然后只需将RSS表视图设置为每个导航控制器的根视图控制器。我假设您需要根据视图所在的选项卡更改行为;只需使用MyAppDelegate*[[UIApplication sharedApplication]delegate].tabBarController.selectedIndex(在viewDidLoad方法中)来设置表 然后,要推送详图视图控制器,只需执行以下惯用代码:
DetailController *detailController = [[DetailController alloc] initWithItem:[self.rssParser.rssItems objectAtIndex:indexPath.row]];
[self.navigationController pushViewController:detailController animated:YES];
[detailController release];
当然,您必须将initWithItem:方法添加到您的细节控制器:
-(id)initWithItem:(RSSItem *)item {
if (self = [super initWithNibName:@"DetailController" bundle:nil]) {
self.item = item;
}
return self;
}
通常,您希望将显示项目的控制权分配给执行显示的视图控制器,而不是试图在应用程序代理中维护中央控制权