小编jim*_*bob的帖子

我可以调用ViewController类中的哪个方法来检查它何时被带到前台?

我可以调用ViewController类中的哪个方法来检查它何时被带到前台?

例如,我在我的应用程序上查看一个页面,然后我决定关闭该应用程序并稍后再回到它.当我回到它时,屏幕上显示的是我所看到的相同视图.但是......一旦我打开应用程序,我想转到另一个视图.

我怎样才能做到这一点?

目前尝试这个:

 - (void) applicationDidBecomeActive:(NSNotification*) notification
{
    [self checkActivity];
    // Do your stuff here
}


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(applicationWillEnterForeground:)
                                                     name:UIApplicationWillEnterForegroundNotification
                                                   object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(applicationDidBecomeActive:)
                                                     name:UIApplicationDidBecomeActiveNotification
                                                   object:nil];
    }
    return self;
}

- (void)checkActivity{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSLog(@"Checking if re-authentication required...");
    if([[defaults objectForKey:@"shouldgotologin"] isEqualToString:@"yes"]){
        NSLog(@"View Should go to login...performing segue");
        [defaults setObject:@"no" forKey:@"shouldgotologin"];
        [defaults synchronize];
        [self performSegueWithIdentifier:@"backtologin" sender:self];
    } else …
Run Code Online (Sandbox Code Playgroud)

iphone ios

1
推荐指数
1
解决办法
622
查看次数

SharedPreferences不存储值

嗨伙计们,我有一个字符串,我试图存储到SharedPreferences:

这是我用来存储字符串的方法:

全球大战:

private ArrayList<String> mListEmailAddresses;
Run Code Online (Sandbox Code Playgroud)

方法:

public void setEmailAddressList(String emailAddress){
    emailAddress.replaceAll(",", "");
    mListEmailAddresses.add(emailAddress);
    SharedPreferences prefs = getSharedPreferences("invitefriends", 0);
    StringBuilder str = new StringBuilder();
    for (int i = 0; i < mListEmailAddresses.size(); i++) {
        str.append(mListEmailAddresses.get(i).toString()).append(",");
    }
    LogUtils.log("emails: " + str.toString());
    String theString = str.toString();
    prefs.edit().putString("emails", theString);
    prefs.edit().commit();

}
Run Code Online (Sandbox Code Playgroud)

每次调用此方法时,都会使用添加到列表中的新电子邮件更新str.toString方法.例如"email1 @ gmail.com,email2 @ yahoo.co.uk,email3 @ hotmail.co.uk"将成为形成的字符串.日志正确显示此字符串.然后我将theString放在关键字"电子邮件"下,每当视图重新启动时,它都会刷新,如下所示:

    SharedPreferences prefs = getSharedPreferences("invitefriends", 0);
    String savedString = prefs.getString("emails", "");
    LogUtils.log("saved emails: " + savedString);
    StringTokenizer st = new StringTokenizer(savedString, ",");
    mListEmailAddresses = new ArrayList<String>(); …
Run Code Online (Sandbox Code Playgroud)

android sharedpreferences

1
推荐指数
1
解决办法
1809
查看次数

条纹布局ios键盘默认隐藏.

我正在使用条带SDK,它创建卡片详细信息的视图.代码如下:

//live key
NSString *cardApiKey;

if([hostType isEqualToString:@"production"])
{
    cardApiKey = @"xxxxxxxxxxxxxxxxxxxxx";
} else {
    cardApiKey = @"xxxxxxxxxxxxxxxxxxxxx";
}

self.stripeView = [[STPView alloc] initWithFrame:CGRectMake(10, _cardDetailsLabel.frame.origin.y+_cardDetailsLabel.frame.size.height+10, 200, 55) andKey:cardApiKey];

[self.canvasView addSubview:self.stripeView];

self.stripeView.delegate = self;
Run Code Online (Sandbox Code Playgroud)

问题是数字键盘键盘默认显示.我不希望每次初始化stripeview时都会弹出数字键盘.我怎么能绕过这个?谢谢.

ios stripe-payments

1
推荐指数
1
解决办法
882
查看次数

启动一个新的Activity但我得到一个ActivityNotFoundException

好吧..当我将手机插入计算机时,它启动应用程序,睡眠()完成后,它会崩溃并显示底部显示的错误.我认为你需要的所有代码都显示在引文中.

真的很困惑我为什么会遇到这个问题.我的mainActivity.java文件看起来像这样:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
Thread timer = new Thread(){
        public void run(){
            try{
                sleep(1000);
            } catch (InterruptedException e){
                e.printStackTrace();
            }finally{
                Intent intent = new             Intent("com.worcestershire.android.Pagetwo", null);
                startActivity(intent);
            }
        }
    };
    timer.start();}
Run Code Online (Sandbox Code Playgroud)

第2页看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" 
android:background="@raw/logo"
>

   <TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="This is Activity 2" />

   <Button android:text="Previous"
    android:id="@+id/Button02"
    android:layout_width="250px"
        android:textSize="18px"
    android:layout_height="55px">
</Button> 


</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

我的清单看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.worcestershire.android"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="7" />

<application
    android:icon="@drawable/maps_launcher"
    android:label="@string/app_name" …
Run Code Online (Sandbox Code Playgroud)

android android-intent android-activity

0
推荐指数
1
解决办法
806
查看次数

没有平移手势的 UIScrollView 上的水平滚动

如何才能在使用 UIScrollView 时不调用平移手势识别器选择器。

我希望能够在不调用平移手势选择器的情况下在滚动视图中滚动。

这是我的平底锅检测功能:

- (void)panDetected:(UIPanGestureRecognizer *)panRecognizer
{

    CGPoint translation = [panRecognizer translationInView:self.view];
    CGPoint imageViewPosition = self.draggableImage.center;
    imageViewPosition.x += translation.x;
    imageViewPosition.y += translation.y;

    self.draggableImage.center = imageViewPosition;
    [panRecognizer setTranslation:CGPointZero inView:self.view];
}
Run Code Online (Sandbox Code Playgroud)

当我在页面底部使用 UIScrollView 时,我不希望它被调用。

uiscrollview ios uipangesturerecognizer

0
推荐指数
1
解决办法
1807
查看次数

不相关,没有用

由于缺乏信息而被删除.请继续前进.

html java string storage

-5
推荐指数
1
解决办法
4560
查看次数