小编Kru*_*nal的帖子

比较iPhone中的两个NSDates

我是iPhone开发人员的新手,

我想比较两个日期,第一个日期将来自数据库说,newDate第二个是今天的日期,

如果今天更大,那么newDate我想显示警报.

这是我的代码片段,

NSString *newDate = [formatter stringFromDate:st];
NSDate *today=[[NSDate alloc]init];

if ([today compare:newDate] == NSOrderedDescending)
{
    NSLog(@"today is later than newDate");        
}
else if ([today compare:newDate] == NSOrderedAscending)
{
    NSLog(@"today is earlier than newDate");        
}
else
{
    NSLog(@"dates are the same");        
}
Run Code Online (Sandbox Code Playgroud)

但它崩溃了,编译时也向我显示了警告 [today compare:newDate]

任何帮助将不胜感激.

iphone comparison nsdate ipad

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

在UIButton上添加Longpress手势和Click事件

我是iPhone新手.

我想在我的按钮上添加长按手势和点击事件,这可能吗?

当我将两个事件添加到按钮然后长按时,我的点击事件被触发(点击我导航到新页面),但我的长按事件永远不会被触发.

这是我的代码片段:

button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(xpos, ypos, 120,130);
[button setBackgroundImage:[UIImage imageNamed:@"ibook2.png"] forState:UIControlStateNormal];
[button setTitle:[NSString stringWithFormat:@"32"]];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchDown];

LongPress = [[UILongPressGestureRecognizer alloc] init];
[LongPress addTarget:self action:@selector(longPressDetected:)];
LongPress.delegate = (id<UIGestureRecognizerDelegate>)self;
[button addGestureRecognizer:LongPress];
[LongPress release];

[self.view addSubview:button];
Run Code Online (Sandbox Code Playgroud)

如何添加这两个事件?

任何帮助将不胜感激.

iphone uibutton ipad uigesturerecognizer long-press

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

Xcode-organizer 不显示应用程序

我为 iPhone 开发了应用程序,现在我想将它提交给商店。

当我点击组织者 - 档案时,它只显示一个叫我的东西QRUI,它没有显示我的应用程序..

现在,我应该如何验证和分发我的应用程序?

请帮忙,我是iOS新手。

iphone xcode info.plist ipad ios

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

处理iOS中的特殊字符,如(ö,Ä,é,ß)

我从URL获取数据,此数据包含特殊字符,例如名称中的字符Désirée.

我想在我的TableView单元格中显示它,但是当我显示它时,它看起来像这样:Dösiröe.

如何正确显示?

获取数据

NSString *jsonString = [NSString stringWithContentsOfURL:[NSURL URLWithString:URL] encoding: NSStringEncodingConversionAllowLossy error:nil];
SBJSON *parser = [[SBJSON alloc] init];
dictShow = [parser objectWithString:jsonString error:nil];
arr=[dictShow copy];
Run Code Online (Sandbox Code Playgroud)

在TableView中显示数据

cell.textLabel.text = [arr objectAtIndex:indexPath.row];
Run Code Online (Sandbox Code Playgroud)

nsstring nsstringencoding

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

UIAlertView在iPhone中被称为Twice

可能重复:
UITableViewCell上的UILongPressGestureRecognizer - 双重调用

我是iPhone新手,

我按下长按钮时显示警报,但是当我按下按钮时,我的警报视图再次被调用.

这是我的代码片段,

- (IBAction)longPressDetected:(UIGestureRecognizer *)gestureRecognizer {

    //Gets text of Button.
    UIButton *btn = (UIButton *)[gestureRecognizer view];
    BtnText= [btn titleForState:UIControlStateNormal];
    NSLog(@"longPressDetected");

    UIAlertView* alert_view = [[UIAlertView alloc]
                               initWithTitle: @"Are you sure want to Delete ?" message:nil delegate: self 
                               cancelButtonTitle: @"Yes" otherButtonTitles: @"No", nil];
    [alert_view show];
    [alert_view release];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{ 
    if (buttonIndex==0) {

        [self ReloadView];
         [alertView dismissWithClickedButtonIndex:0 animated:TRUE];
    }
    else{
        [alertView dismissWithClickedButtonIndex:1 animated:TRUE];
    }
}
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激.

编辑:

  -(void)viewWillAppear:(BOOL)animated
   {
         for(int i=0;i<10i++)
            {

                if(i!=0)
                { …
Run Code Online (Sandbox Code Playgroud)

iphone uialertview ipad uigesturerecognizer ios

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

无法使用ios中的Storyboard删除导航控制器中的BackButton

我是iOS新手,

我正在使用Storyboard为iPhone开发购物App,

这是我的应用程序的快照, TabBarController 包含4个标签 NavigationController

当我打开Tab1(让我说class1)它包含TableView,onclick of tableview它将带我到Detail page标题和后退按钮NavigationBar(我正在以编程方式添加标题和后退按钮ViewWillAppear method)之后,当我点击后退按钮我正确导航到上一页,这工作得很好..

我的问题是当我打开Tab1(即class1)并且当我Detail page在tableview中选择一行后导航到a Detail page,BackBtn并且将在NavigationBarbcoz中添加标题ViewWillAppear method将被调用,当我Tab2在击中Backbtn之前点击时,我导航到类Tab2当我回来时Tab1,现在我点击后退按钮我正在导航到我的前一页Tab1 class(即class1),但在class1 后面按钮和标题Detail page是我的,class1我无法隐藏它...

你可以在第二张图片中看到BackBtn并且TitleClass1... 有什么问题 ?

iphone back-button storyboard uinavigationcontroller ios

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

ZBarReader仅扫描iOS 6中的UPC_A格式

我在iOS 6中开发BarCode阅读器应用程序,

我使用ZBar sdk,我用这个开发应用 教程.. 当我对其进行扫描只扫描产品条形码的任何UPC格式,但它并不像扫描任何其他格式的产品EAN_13Code_128等.

这是我的代码片段,

- (IBAction) scanButtonTapped
{

    ZBarReaderViewController *reader = [ZBarReaderViewController new];
    reader.readerDelegate = self;
    reader.supportedOrientationsMask = ZBarOrientationMaskAll;

    ZBarImageScanner *scanner = reader.scanner;

    [scanner setSymbology: ZBAR_I25
                   config: ZBAR_CFG_ENABLE
                       to: 0];

    [self presentViewController:reader animated:YES completion:nil];

}

- (void) imagePickerController: (UIImagePickerController*) reader
 didFinishPickingMediaWithInfo: (NSDictionary*) info
{
    id<NSFastEnumeration> results =
    [info objectForKey: ZBarReaderControllerResults];
    ZBarSymbol *symbol = nil;
    for(symbol in results)
        break;

    NSLog(@"symbol.data=%@",symbol.data);

    [reader dismissViewControllerAnimated:YES completion:nil];

}
Run Code Online (Sandbox Code Playgroud)

如何扫描所有类型的产品?任何的想法 ?

iphone barcode-scanner ipad zbar-sdk ios6

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

这是在iOS中调用方法的正确方法

我曾经使用iOS,但我没有得到这个所有方法有什么区别,

我应该使用哪种语法来调用MehodName

 (1) [self MehodName];

 (2) [self performSelector:@selector(MehodName) withObject:nil];

 (3) [self performSelectorInBackground:@selector(MehodName) withObject:nil];

 (4) [self performSelectorOnMainThread:@selector(MehodName) withObject:nil waitUntilDone:YES];

 (5) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 
                                         (unsigned long)NULL), ^(void) {
    [self MehodName];
});

  (6) dispatch_sync(dispatch_get_main_queue(), ^{
     [self MehodName];       
});
Run Code Online (Sandbox Code Playgroud)

请提前帮助和谢谢.

objective-c method-call

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

searchBarTextDidBeginEditing在后退按钮单击时再次调用委托方法

我正在开发iPhone应用程序,其中我一度陷入困境.

我有一个viewController隐藏了导航栏,搜索栏位于页面的中心.

当用户点击searchBar searchBarTextDidBeginEditing方法被触发时.

在此之后,在searchBar textDidChange方法的文本更改中,我在tableview中加载实时数据,并在点击tableview时导航到其他页面,导航栏未隐藏.

现在,当我再次按回按钮时,我来到搜索页面这里searchBarTextDidBeginEditing方法再次被解雇.

为什么在背压下再次调用此方法?

请提前帮助和感谢.

objective-c uitableview uisearchbar ios

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

检查时间是否落在两次iOS之间

我有两次说8.40am和4.00pm,我想做的是,想检查当前时间是否在给定时间之间?

我已经尝试过这段代码,但它无法正常工作:(你能帮我解决我犯错的地方吗?

NSDateComponents *components = [[NSCalendar currentCalendar] components:NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit fromDate:[NSDate date]];
    NSInteger currHr = [components hour];
    NSInteger currtMin = [components minute];

    NSString startTime = @"21:00";
    NSString endTime = @"07:00";
NSArray *arr=[NSArray arrayWithObjects:startTime,endTime, nil];

    int stHr = [[[[arr objectAtIndex:0] componentsSeparatedByString:@":"] objectAtIndex:0] intValue];
    int stMin = [[[[arr objectAtIndex:0] componentsSeparatedByString:@":"] objectAtIndex:1] intValue];
    int enHr = [[[[arr objectAtIndex:1] componentsSeparatedByString:@":"] objectAtIndex:0] intValue];
    int enMin = [[[[arr objectAtIndex:1] componentsSeparatedByString:@":"] objectAtIndex:1] intValue];

    int formStTime = (stHr*60)+stMin;
    int formEnTime = (enHr*60)+enMin;

    int nowTime = (currHr*60)+currtMin; …
Run Code Online (Sandbox Code Playgroud)

cocoa-touch objective-c nsdate nsdateformatter ios

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