我正在尝试以下代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
Thing *sub = [[subscriptions objectAtIndex:indexPath.row] retain];
StoriesViewController *thing = [[StoriesViewController alloc] initWithThing:sub];
thing.navigationController.title = sub.title;
[self.navigationController pushViewController:thing animated:YES];
[thing release];
[sub release];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
我认为这是你正确设置推动控制器的标题的方式.我尝试了thing.title但是设置了TabBarItem的标题.
我正在开发一个iOS应用程序,它使用一个非常常见的基于Core Data的tableview来显示项目,当它选择一个时,它会显示更详细的视图,就像Contacts应用程序一样.详细视图本身是一个以编程方式生成的分组表,其中包含具有图片和名称的标题的自定义(nib定义)视图.表中的一些单元格是具有标签名称和文本框值的自定义单元格.在"编辑"模式下,可编辑的表格单元格(以及标题中的名称)将.clearButtonMode设置为UITextFieldViewModeAlways以显示它们是可编辑的.
我目前正在使用相同的视图控制器来显示详细信息,编辑信息,并将新记录添加到原始列表.
添加新项目时,视图控制器是以模态方式创建的,具有自定义init重载,该重载在视图控制器中设置标志以指示它正在添加记录.这允许它以编辑模式启动,如果保留编辑模式,则模型视图将被删除.右侧菜单栏按钮是通常的编辑/完成,左侧是取消按钮.当正在编辑现有项目时,左按钮(正常后退按钮)将替换为取消按钮.
我开始重新考虑是否有一个视图控制器处理三种不同的模式是要走的路.有几个问题我不知道如何处理.
1)如何通过点击"完成"来判断是否保留编辑模式?它有行动吗?如果单击取消,则操作将自行解除(添加模式)或恢复先前的值离开编辑模式.我想我可以检查我的setEditing覆盖来处理它,但似乎应该有更好的方法.
2)当进入编辑模式并且我将可编辑的文本字段设置为UITextFieldViewModeAlways时,有没有办法动画"X"按钮的外观,以便它们与常规单元格上的编辑指示器一起淡入?
是否有解决这些问题的简单方法,或者我的三合一视图控制器是个坏主意?对于不同的模式重新制作相同的视图似乎并不正确,但是为视图控制器设置多种模式似乎有点麻烦.
jorj
model-view-controller uitableview uinavigationcontroller ios
我正在尝试使用sharekit在Twitter和Facebook上发布.
我有两个按钮,它们调用以下两种方法:
- (IBAction) shareOnFacebook:(id)sender
{
// Create the item to share
NSString *someText = @"Share on Facebook.";
SHKItem *item = [SHKItem text:someText];
// Share the item
[[SHK currentHelper] setRootViewController:self.navigationController];
[SHKFacebook shareItem:item];
}
- (IBAction) shareOnTwitter:(id)sender
{
// Create the item to share
NSString *someText = @"Share on Twitter.";
SHKItem *item = [SHKItem text:someText];
//tried both methods to set navigationcontroller!
[[SHK currentHelper] setRootViewController:self.navigationController];
[SHK setRootViewController:self.navigationController];
[SHKTwitter shareItem:item];
}
Run Code Online (Sandbox Code Playgroud)
Facebook只是工作,当我尝试使用Twitter时,我收到以下错误:
2011-05-31 10:20:25.928 App[870:707] *** Assertion failure in -[SHK showViewController:], /Users/blaat/Dropbox/App/Classes/ShareKit/Core/SHK.m:112
2011-05-31 …Run Code Online (Sandbox Code Playgroud) 我有几个UIViewControllers,通过UINavigationController加载,我覆盖loadView,并设置一个自定义视图来显示.我在设置某些子视图的帧时遇到问题,也许是视图本身.我认为UINavigationController或UIViewController能够强制它的视图在显示时填充屏幕.
我想知道是否和/或何时设置了视图的大小.如果它正在发生,它是设置视图的框架,还是以另一种方式.
谢谢.
更新:我刚刚注意到,在解决这个问题时,我使用这个loadView方法创建了一个新的UINavigationController:
- (void)loadView
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(10.0f, 10.0f, 10.0f, 10.0f)];
[view setBackgroundColor:[UIColor redColor]];
self.view = view;
[view release];
}
Run Code Online (Sandbox Code Playgroud)
除了状态栏和标题之外,我得到一个占据整个屏幕的红色视图.我的视图什么时候调整大小以填满屏幕?在创建视图时我应该使用多大的尺寸?
我需要一点导航控制器问题的帮助.
我有navigationController4 ViewControllers推.推送的最后一个vc进一步提供了ViewController模态.模态ViewController提出了一个ActionSheet.根据用户的回答,我要么ViewController仅解除模态,要么我想回到根目录ViewController.
在ViewController提出的模态中,我有:
- (void) dismissGameReport
{
[[self delegate] GameReportModalWillBeDismissed:modalToPopToRoot];
}
Run Code Online (Sandbox Code Playgroud)
在最后ViewController推入navigationController堆栈我有:
- (void)GameReportModalWillBeDismissed: (BOOL)popToRoot;
{
if (popToRoot)
{
[self.navigationController popToRootViewControllerAnimated:NO];
}
else
{
[self dismissModalViewControllerAnimated:YES];
}
}
Run Code Online (Sandbox Code Playgroud)
解雇模态视图控制器工作正常.然而,
[self.navigationController popToRootViewControllerAnimated:NO];
Run Code Online (Sandbox Code Playgroud)
不会导致root ViewController显示其视图.添加一些日志信息我看到在self.navigationController正确弹出到堆栈的消息之后,执行依次继续.屏幕仍然显示模态ViewController的视图.
作为一种解决方法,我尝试总是解雇模态视图控制器,并在ViewWillAppear方法中有popToRootAnimated消息.没有不同.仍会弹出一堆控制器,但屏幕会继续显示我的模态视图控制器的视图,并继续按顺序执行.
有人可以帮帮我吗?
在这里,我有2个意见:
首先,AppDelegate通过以下代码调用WelcomeVC:
- (void)presentWelcomeViewController
WelcomeViewController *welcomeViewController = [[WelcomeViewController alloc] initWithNibName:@"WelcomeViewController" bundle:nil];
welcomeViewController.title = @"Welcome to My App";
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:welcomeViewController];
navController.navigationBarHidden = YES;
self.viewController = navController;
self.window.rootViewController = self.viewController;
}
Run Code Online (Sandbox Code Playgroud)
因此,在WelcomeVC中,导航栏不显示为navController.navigationBarHidden = YES;。在WelcomeVC中,有一个按钮来调用WebViewVC,如下所示:
- (IBAction)termsPressed:(id)sender {
WebViewController *webViewController = [[WebViewController alloc] initWithNibName:nil bundle:nil];
NSLog(@"Terms of Use");
webViewController.urlPassed = @"http://.../term.html";
webViewController.title = NSLocalizedString(@"Terms of Use", nil);
[webViewController.navigationController setNavigationBarHidden:NO animated:NO];
[self.navigationController presentViewController:webViewController animated:YES completion:^{}];
} …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我有一个UITabBarController作为根视图.我有两步模态视图,将使用导航控制器进行导航.我遇到了一个问题,当我将UINavigationController作为UITabBarController的子项添加时,导航控制器底部会留下一个标签条大小的间隙.请参阅附图(对于丑陋的道歉,它仅用于演示目的).
在图像中,底部白色条是标签栏,蓝色背景是当前选定标签的视图控制器.黄色是导航控制器中包含的视图控制器.红色是将导航控制器作为子项添加到选项卡栏控制器时创建的间隙.
仅当选项卡栏设置为不透明时才会发生这种情况.用于导航控制器上的扩展布局的边缘没有区别.似乎无论我做什么,我都留下了我无法做任何事情的差距.
我正在以一种非常简单的方式添加导航控制器:
addChildViewController(navigationController)
view.addSubview(navigationController.view)
navigationController.view.setTranslatesAutoresizingMaskIntoConstraints(false)
view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-20-[view]-20-|", options: nil, metrics: nil, views: ["view" : navigationController.view]))
view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-100-[view]-100-|", options: nil, metrics: nil, views: ["view" : navigationController.view]))
Run Code Online (Sandbox Code Playgroud)
如果我将导航控制器设置为应用程序委托中的根视图控制器,它将正确显示,底部没有间隙.
这是标签栏和导航控制器之间交互的错误还是我可以做些什么来防止这种情况?
我正在使用Objective-C/Swift编写的现有iOS应用程序中集成组件.
作为我的应用程序的根视图控制器,我使用了UINavigationController.
在我的应用程序的多个视图控制器之一中,我有一个按钮,可以在导航控制器中推送包含以下代码的视图控制器:
@objc class ReactNativeViewController: UIViewController {
override func viewDidLoad() {
let jsCodeLocation = NSURL(string: "http://localhost:8081/index.ios.bundle?platform=ios&dev=true")
let contactsView = RCTRootView(bundleURL: jsCodeLocation, moduleName: "MainComponent", initialProperties: nil, launchOptions: nil)
self.view.addSubview(contactsView)
contactsView.frame = self.view.bounds;
}
}
Run Code Online (Sandbox Code Playgroud)
MainComponent返回一个Navigator管理多个React-Native组件的东西:
return (
<Navigator
initialRoute={initialRoute}
renderScene={(route, navigator) => {
if (route.component) {
return <route.component navigator={navigator} {...route.passProps} />;
}
}}
navigationBar={
<Navigator.NavigationBar
routeMapper={this.NavigationBarRouteMapper}
style={styles.navBar}
/>
}
/>
);
Run Code Online (Sandbox Code Playgroud)
该工作流程正常.我唯一需要的是流行的方式ReactNativeViewController从我UINavigationController当按钮Back被击中的主要阵营本地组件.
我试过以下但没有运气:
使用单个方法创建一个本机模块,该方法popLastViewController弹出从UINavigationController显示的显示的UIViewController:
@implementation RNNavigationControllerBridge
RCT_EXPORT_MODULE() …Run Code Online (Sandbox Code Playgroud)我正在尝试在弹出过渡期间为导航栏的backgroundImage设置动画。
我意识到backgroundImage不是一个可设置动画的属性,但是我已经能够在推送过程中通过在以下之间进行转换的视图控制器的viewWillAppear方法中使用CATransition实现此目的:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let animation = CATransition()
animation.duration = 0.3
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
animation.type = kCATransitionFade
navigationController?.navigationBar.layer.add(animation, forKey: nil)
navigationController?.navigationBar.setBackgroundImage(navigationBarBackgroundImage, for: .default)
}
Run Code Online (Sandbox Code Playgroud)
我希望它在弹出期间也能正常工作,但是发生的是导航栏突然在弹出动画完成后突然显示下一个视图控制器的背景图像(未动画)。
我还尝试将上述尝试与过渡协调器组合在一起,但是在弹出完成后图像突然改变的情况下,它会产生完全相同的结果。
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
transitionCoordinator?.animate(alongsideTransition: { [weak self] (context) in
let animation = CATransition()
animation.duration = 0.3
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
animation.type = kCATransitionFade
self?.navigationController?.navigationBar.layer.add(animation, forKey: nil)
self?.navigationController?.navigationBar.setBackgroundImage(navigationBarImage, for: .default)
}, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
具体来说,我正在寻找一种可在iOS9和iOS10上运行的方法。
应用程序导航到VC1到VC2,在VC2中"返回","菜单"和"提交"按钮在点击"提交"时显示一条带有消息的警报,单击"确定"按钮时显示"确定"按钮I'我试图弹出到VC1,代码正在执行但导航没有发生.
"返回"和"菜单"按钮也发生了同样的事情,代码正在执行,但没有导航到任何其他页面.使用Xcode 9 beta 6.
我在我的项目中使用的下面一段代码
NSArray *controllersArray = [[self navigationController] viewControllers];
for(UIViewController *controller in controllersArray)
{
if ([controller isKindOfClass:[ViewController1 class]])
{
ViewController1 *accDetailVC = (ViewController1*)controller;
[[self navigationController] popToViewController:accDetailVC animated:YES];
break;
}
}
Run Code Online (Sandbox Code Playgroud)
在iOS 11 beta以外的其他iOS版本中工作.如果任何人面临同样的问题,请帮助我.
objective-c uiviewcontroller uinavigationcontroller nsarray ios11
ios ×7
objective-c ×3
iphone ×2
cocoa-touch ×1
ios11 ×1
ios4 ×1
nsarray ×1
oauth ×1
react-native ×1
sharekit ×1
swift ×1
swift3 ×1
twitter ×1
uitableview ×1
uiview ×1