我有一个应用程序,我需要在每1或2秒后调用一个实例方法.现在,如果我放置
[self performSelector:@selector(getMatchListWS) withObject:nil afterDelay:1.0];
Run Code Online (Sandbox Code Playgroud)
在viewDidLoad:或viewWillAppear:中,方法getMatchListWS仅在视图出现或加载时被调用一次.但是我需要连续调用该方法,即使用户在该视图上而视图没有消失或卸载.那么,我可以添加performSelector方法的正确位置或委托方法是什么,以便每秒调用它而不必一次又一次地卸载视图.我是否需要在后台或主线程中执行某些操作.提前致谢!!
在将viewController推入导航控制器之后,viewController的视图不会被加载.
这是我的代码片段.
- (void)myMethodInClassA {
// window's root view controller is navigation controller
UINavigationController *naviCtrl = (UINavigationController*)[UIApplication sharedApplication].keyWindow.rootViewController;
MyViewController *myVC = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
[naviCtrl pushViewController:myVC animated:NO];
// at this point, myVC's view is NOT loaded
}
Run Code Online (Sandbox Code Playgroud)
当我打电话时myMethodInClassA,myVC viewDidLoad被称为AFTER,该方法返回.我希望在pushViewController:animated:调用导航控制器之后和myMethodInClassA返回之前加载myVC的视图.
何时加载了视图控制器的视图?Apple的文档只是说它在首次访问时已加载.这有点模棱两可.为什么导航控制器的pushViewController:访问视图控制器没有视图?
抱歉抱歉最初的模棱两可的问题.
我正在实现自己的"后退"按钮.其中onClick,以下代码在ViewController被解雇的(VC)中执行:
navigationStack navigationStack,然后使用它presentViewController
后面的工作是视觉上有效的 - 即当前VC消失,之前VC出现.但是,viewDidLoad不调用该方法.因此,屏幕不会更新数据更新viewDidLoad.
[self dismissCurrentViewController:self completion:^{
[TWStatus dismiss];
FHBaseViewController *vcToDisplay = [[FHDataManager sharedInstance] popNavigationStack];
[vcToDisplay.homeVC presentViewController:vcToDisplay animated:NO completion: ^{ }];
}];
Run Code Online (Sandbox Code Playgroud)
问题:
viewDidLoad在presentViuewController使用时总会被调用?viewDidLoadVC#2中的一个名为ONLY的方法"构建"屏幕.iOS如何在不显示屏幕的情况下显示viewDidLoad?顺便说一下,我没有使用故事板.任何帮助表示赞赏!
我试图UIImageView眨眼viewDidLoad.我不确定最好的办法是什么.我已经使用循环与尝试.hidden=YES和.hidden=NO,但是这似乎是一个不错的方法来做到这一点.我需要一些适当的建议.
我需要了解UIView何时出现在屏幕上,所以我需要一个viewDidAppear方法的类比.
我找到了一个UIView生命周期:
我尝试了所有这些方法,但我没有得到答案.
我很长一段时间一直是这个网站的忠实粉丝,但这是我发布的第一个问题.
我已经阅读了与主题相似的每个帖子(我认为),但他们都使用NIB文件. 我的项目中的任何地方都没有nib文件.
这是一个带有一个视图的简单项目(这意味着一个委托类,一个uiviewcontroller类和一个uiview类),我的视图显示正常,除了从未调用viewDidLoad方法.
main.m看起来像这样:
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, @"MyAppDelegate");
[pool release];
return retVal;
}
Run Code Online (Sandbox Code Playgroud)
MyAppDelegate.m看起来像这样:
-(void)applicationDidFinishLaunching:(UIApplication *)application{
UIWindow *localWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window = localWindow;
[localWindow release];
MainViewController *viewController = [[MainViewController alloc] init];
//Option 1
navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
////Option 2
//navigationController = [[UINavigationController alloc] init];
//navigationController.viewControllers = [NSArray arrayWithObject:viewController];
////Option 3
//navigationController = [[UINavigationController alloc] init];
//[navigationController pushViewController:viewController animated:NO]; …Run Code Online (Sandbox Code Playgroud) 是否有可能在加载视图时加载UITableView的所有单元格,以便在我滚动时不加载它们?(这样做时我会显示一个加载屏幕)
拜托,这是我项目的唯一方式(抱歉太复杂,无法解释为什么^^)
编辑:
好的,让我解释一下,我明确在做什么:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellIdentifier = [NSString stringWithFormat:@"Identifier %i/%i", indexPath.row, indexPath.section];
CustomTableCell *cell = (CustomTableCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
NSDictionary *currentReading;
if (cell == nil)
{
cell = [[[CustomTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];
UILabel *label;
UIView *separator;
if(indexPath.row == 0)
{
// Here I'm creating the title bar of my "table" for each section
}
else
{
int iPr = 1;
do
{
currentReading = [listData objectAtIndex:iPr-1];
iPr++;
} while (![[currentReading valueForKey:@"DeviceNo"] isEqualToString:[devicesArr objectAtIndex:indexPath.section]] …Run Code Online (Sandbox Code Playgroud) 应该在init方法中使用的代码类型(对象分配,设置ui元素,网络调用等)与视图控制器的viewDidLoad类型方法之间的差异的一般准则是什么?
当我的应用程序从后台进入前台时,是否有一种简单的方法来调用方法?我的程序在viewDidLoad方法中调用了一个方法"nowYouSeeMe",这在第一次运行应用程序时效果很好.当我使用应用程序然后按下主页按钮时,它会像往常一样移动到背景.现在,当我按下应用程序图标并将其带到前台时,我基本上希望它再次调用nowYouSeeMe方法.
-(void)nowYouSeeMe{
NSLog(@"I'm back");
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗??
我在中创建了一个URL方案Info.plist来调用我的应用程序,但是URL还会解析我需要读取的数据字符串。
环顾了一会后,我发现-http: //www.informit.com/articles/article.aspx?p= 2301787&seqNum =2
用下面的代码
var scheme: String!
var path: String!
var query: String!
func application(app: UIApplication, openURL url: NSURL, options: [String: AnyObject]) -> Bool {
scheme = url.scheme
path = url.path
query = url.query
return true
}
Run Code Online (Sandbox Code Playgroud)
据称,每当我通过URL调用应用程序时都会调用该函数,但是却从未调用过该函数,而且我无法想象我必须将该函数放入中viewDidLoad,如果我确实将其放入中,viewDidLoad那么它将每次都被调用该应用程序已启动。
我是在错误的假设吗-不需要在中调用该函数,viewDidLoad或者是否有更好的方法使用Info.plist创建方案从URL方案获取数据
viewdidload ×10
ios ×9
objective-c ×4
xcode ×2
foreground ×1
info.plist ×1
methods ×1
swift ×1
uiimageview ×1
uitableview ×1
uiview ×1
url-scheme ×1