我想要实现的是在单击我的警报视图按钮时转到另一个视图.我的警报视图在我的loadingView中,这个警报视图是从另一个名为classA的类中调用的.
[LoadingViewController showError];
Run Code Online (Sandbox Code Playgroud)
+ (void)showDestinationError{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Error"
message:@"Error"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
alert.tag = DEST_ERR;
[alert show];
}
Run Code Online (Sandbox Code Playgroud)
+ (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(alertView.tag = DEST_ERR){
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]];
UINavigationController *secondView = [storyboard instantiateViewControllerWithIdentifier:@"NavigationController"];
secondView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[secondView presentModalViewController:secondView animated:YES];
}
}
Run Code Online (Sandbox Code Playgroud)
我试图使用一个按钮从一个视图(XIB)转到另一个视图.我正在使用Xcode 4.3.2和iOS 5.我首先创建项目(Single View Application).然后我在Interface Builder中创建我的按钮,在头文件中创建我的插座,在.m文件中创建我的IBAction.接下来,我右键单击Xcode中的项目文件夹并选择"新建文件".然后我选择了"Object-C Class"并将其命名为"SecondViewController".创建了两个新文件,"SecondViewController.h"和"SecondViewController.m".然后我回去右键单击Xcode中的项目文件夹,选择"新建文件",然后从"用户界面"选项中选择"查看".
现在我有我的空IBAction(我的按钮),我想用它去一个新的视图,叫做SecondViewController.xib.
如果到目前为止创建新的XIB和.h/.m文件是正确的,那么我将如何使用我的按钮"转到"或显示我的第二个视图?请记住,我仍然处于初级水平,我感谢任何帮助和耐心:)
我可以在主View和我的SecondView之间区分的唯一区别是在头文件中:
主视图头文件:
@interface ButtonToNewViewViewController : UIViewController
Run Code Online (Sandbox Code Playgroud)
第二个View头文件:
@interface SecondViewController : NSObject
Run Code Online (Sandbox Code Playgroud)
IBAction为:
-(IBAction)nextView:(id)sender
{
// go to new view
}
Run Code Online (Sandbox Code Playgroud) 看起来像UINavigationBar的Back按钮使用视图控制器的标题作为标题,如果前一个视图控制器没有标题,它使用Back,但是有一种方法可以自定义后退按钮的标题,无论标题是什么以前的视图控制器有?
谢谢
objective-c uinavigationbar uinavigationcontroller viewcontroller ios
出于某种原因,我的导航控制器没有正确推动.
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"HERE!");
MyViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"myVC"];
vc.labelText = [self.myArray objectAtIndex:indexPath.row];
[self.navigationController pushViewController:vc animated:YES];
NSLog(@"Pushed");
}
Run Code Online (Sandbox Code Playgroud)
输出是:
2014-02-17 12:41:47.187 TableViewTesting[37532:70b] HERE!
2014-02-17 12:41:47.189 TableViewTesting[37532:70b] Pushed
Run Code Online (Sandbox Code Playgroud)
所以它一切正常,但我仍然只是在点击一个单元格后才看到我的初始视图控制器.
我正在学习Objective C&Xcode,通过我的第一个应用程序.首先,用户必须登录.然后他可以做几件事,比如加入团队或更改他的数据(用户名,电子邮件......).
登录完成,它工作正常.对于这个问题:
是否可以设置一个我可以从每个View Controller获得的变量?
我尝试使用segues,但我认为在每个View Controller中定义它都非常困难.
我正在寻找一个全局变量,我可以从应用程序的任何地方到达,这可能吗?或者还有其他方法可以解决这个问题吗?
感谢您的帮助!伊曼纽尔
我在Xcode上不断收到错误,我该如何帮助呢?
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
Run Code Online (Sandbox Code Playgroud)
在这里,我不赞成使用'presentModalViewController:animated'。在IOS 6.0中首次弃用。
-(IBAction)SetMap:(id)sender {
Run Code Online (Sandbox Code Playgroud)
在这里,我不赞成使用'UIAlertView':在iOS 9.0中不赞成使用-UIAlertView不赞成使用。改用UIAlertController和UIAlertControllerStyleAlert的preferredStyle。
}
Run Code Online (Sandbox Code Playgroud)
在花括号之后,我不赞成使用“ dismissModalViewControllerAnimated:”:在iOS 6.0中首先不赞成使用。
- (IBAction)Aktiekurs:(id)sender {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.euroinvestor.dk/boerser/nasdaq-omx-copenhagen/novozymes-b-a-s/239698"]];
}
Run Code Online (Sandbox Code Playgroud)
最后,我不赞成使用“ dismissModalViewControllerAnimated:”:在iOS 6.0中第一次不赞成使用。
我NSTimer用来在我的firebase数据库中查找更新.我把代码放在我的内部viewDidLoad().
NSTimer.scheduledTimerWithTimeInterval(5.0, target: self, selector: #selector(DriversInterfaceViewController.CheckFormularChild), userInfo: nil, repeats: true)
Run Code Online (Sandbox Code Playgroud)
当用户在数据库中收到文件时,我希望用户转到另一个文件ViewController.问题是旧的ViewController是在后台运行还是计时器在更改时不会停止View Controller.
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewControllerWithIdentifier("recievedMission") as! RecievedMissionViewController
self.navigationController!.pushViewController(nextViewController, animated: true)
Run Code Online (Sandbox Code Playgroud)
我如何解雇旧的View Controller或如何停止NSTimer programmatically?谢谢!
我使用导航控制器从一个视图推送到另一个视图,但没有弹出任何我推送的视图。因此,在加载视图时,我想从堆栈中弹出上一个视图。
推送视图的代码:
var identities = [String]()
identities = ["A", "B", "C", "D", "E"]
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let vcName = identities[indexPath.row]
let viewController = storyboard?.instantiateViewController(withIdentifier: vcName)
self.navigationController?.pushViewController(viewController!, animated: true)
}
Run Code Online (Sandbox Code Playgroud)
用于弹出视图的测试代码(不是我想要的):
self.navigationController?.viewControllers.remove(at: 0)
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激。
解决了:
@DonMag帮助我逐步了解了该行代码的正确使用和放置。
memory-leaks uinavigationcontroller viewcontroller ios swift
当我尝试按创建UIButton对象的ViewController顺序将对象链接到类时IBAction,Xcode不会向我显示创建该对象的窗口。我不得不说,它仅与第二发生ViewController的NavigationController,因为它的作品的第一个。我相信这应该是Xcode错误...情况如下:
我已经阅读了有关此问题的几篇文章,但都没有解决我的问题。
我正在编写一个应用程序,我必须单击一个按钮(“准备”)以转到以下ViewController。单击该按钮时,它还会在两个视图控制器之间传递数据。
问题是,当我单击按钮时,以下ViewController加载两次。因此,如果我想返回,则必须返回两个相同的ViewController。
我已经检查了segue,类名和文件名,但没有任何修复方法。
我还创建了一个新项目,并从一开始就重写了所有代码,但最后仍然无法正常工作。
但是,我注意到在添加prepare(forSegue :)函数和performSegue函数时出现了问题。没有它,ViewController只会加载一次。但是,当然,没有它我就无法在视图之间传递数据。
这是我的两个视图的屏幕快照以及两个函数的代码:
// Prepare the segue
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "prepareSegue" {
let timerViewController = segue.destination as! CountdownViewController
timerViewController.timeInterval1 = waitingTime
timerViewController.timeInterval2 = shootingTime
timerViewController.lastSeconds = lastSeconds
timerViewController.currentTimeInterval = waitingTime
}
}
// Prepare the timer when the button is pushed
@IBAction func prepareTimer(_ sender: Any) {
performSegue(withIdentifier: "prepareSegue", sender: self)
}
Run Code Online (Sandbox Code Playgroud) viewcontroller ×10
ios ×9
swift ×4
xcode ×4
objective-c ×3
alertview ×1
cocoa-touch ×1
iphone ×1
memory-leaks ×1
nstimer ×1
segue ×1
storyboard ×1
tableview ×1
uialertview ×1
uikit ×1
view ×1
viewdidload ×1