小编Dee*_*san的帖子

在django_simple_history中使用prefetch_related

我有一个模型预订,其中有一个历史.像这样,我使用django_simple_history

class Booking(CreatedAtAbstractBase):
    history = HistoricalRecords()
Run Code Online (Sandbox Code Playgroud)

我使用管理命令来完成任务.我想在预订时预取历史记录

booking_p_history = Booking.history.filter(s_id=6).order_by(
                'updated_at').first()    
booking_obj_list = Booking.objects.select_related(...) \
                    .prefetch_related(
                    Prefetch('booking_history', queryset=booking_p_history, to_attr='driver_pickup_history')
                    ,'booking_history') \
                    .filter(...)
Run Code Online (Sandbox Code Playgroud)

如何在预取中使用简单的历史记录?

python django prefetch django-simple-history

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

UITextField:密码实施

我有一个OTP屏幕,我必须在4个Diff TextFields中输入4位数密码的OTP,场景如下:

在此输入图像描述

  1. 每个文本字段的最大字符数限制为1,当用户在文本字段中输入字符时,它应移动到下一个TextField.
  2. 当用户点击后退空间时,它应该回到之前的文本字段以进行更改.

我已经管理了高达70%的工作,但只有当用户输入所有textField时,后退空间才有效.我正在粘贴我的代码.

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    // This allows numeric text only, but also backspace for deletes
    if (string.length > 0 && ![[NSScanner scannerWithString:string] scanInt:NULL])
        return NO;

    NSUInteger oldLength = [textField.text length];
    NSUInteger replacementLength = [string length];
    NSUInteger rangeLength = range.length;

    NSUInteger newLength = oldLength - rangeLength + replacementLength;

    // This 'tabs' to next field when entering digits
    if (newLength == 1) {
        if (textField == _pin1)
        {
            [self performSelector:@selector(setNextResponder:) withObject:_pin2 afterDelay:0];
        }
        else …
Run Code Online (Sandbox Code Playgroud)

objective-c uitextfield ios uitextfielddelegate

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

通过Autolayout推动隐藏底栏

我有UITabBarController一个UINavigationController拿着一个UIViewController根视图控制器.

当点击其中一个按钮时UIViewController,我按下一个常规聊天窗口UIViewController(用TableView +输入视图)结束隐藏底部标签栏.(使用"按下时隐藏底栏"标志)

在故事板中,我UIView向VC 添加了一个看起来像底栏的常规子类,我使用自动布局将其固定到VC视图的底部.

我推VC时的问题需要一秒钟才能将此视图固定到底部,看起来像自动布局将其固定到底部,就像标签栏没有隐藏一样,一秒后它就会识别出标签栏是隐藏的将其移动到视图的真实底部.

有关清晰信息,请查看此屏幕截图

在此输入图像描述

现在我将让你知道表视图的约束. 在此输入图像描述

现在我展示了InputView的约束 在此输入图像描述

我也在添加我的View层次结构......

在此输入图像描述

objective-c uitabbarcontroller ios autolayout xcode7

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

UIPageViewController iOS 8的下一页按钮 - objC

实际上我正在尝试使用PageViewController填充图库.我成功地在视图中添加了滚动图像但是,我在页面View Controller中使用了Next和Previous按钮,但是我使用了这行代码.

- (IBAction)previousButtonPressed:(id)sender {
    PageContentViewController *startingViewController = [self viewControllerAtIndex:0];
    NSArray *viewControllers = @[startingViewController];
    [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionReverse animated:NO completion:nil];
}

- (IBAction)nextButtonPressed:(id)sender {
    PageContentViewController *startingViewController = [self viewControllerAtIndex:+1];
    NSArray *viewControllers = @[startingViewController];
    [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
    }
Run Code Online (Sandbox Code Playgroud)

因为我在- (IBAction)nextButtonPressed:(id)发送者使用了viewControllerAtIndex:+1我只是在第一次点击按钮动作时才使按钮动作正常工作.提前致谢

objective-c button ios uipageviewcontroller

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

本地通知横幅和声音在前景Objective-C中不起作用

我试图实现本地通知到我的应用程序,我实现了本地通知,但问题是.... 当我的应用程序在前台时,我没有收到通知BANNER和SOUND.但是当我的应用程序处于后台时,它运行良好.如何将通知横幅和声音带到前台..这可能吗?

这是我的一段代码......

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Handle launching from a notification
    UILocalNotification *locationNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
    if (locationNotification) {
        // Set icon badge number to zero
            application.applicationIconBadgeNumber = 0;
    }
}

- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
{

    if (application.applicationState == UIApplicationStateActive ) {
        NSLog(@"it entered active push");

        UILocalNotification *localNotification = [[UILocalNotification alloc] init];
        localNotification.userInfo = userInfo;
        localNotification.soundName = UILocalNotificationDefaultSoundName;
        localNotification.alertBody = userInfo[@"aps"][@"alert"][@"body"];
        localNotification.alertLaunchImage= userInfo[@"acme1"];
        localNotification.fireDate = [NSDate date];
        localNotification.applicationIconBadgeNumber = …
Run Code Online (Sandbox Code Playgroud)

objective-c ios uilocalnotification

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