Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 修正错误:日期值适用于iPhone,但不适用于iPad_Ios_Objective C_Iphone_Ipad_Logging - Fatal编程技术网

Ios 修正错误:日期值适用于iPhone,但不适用于iPad

Ios 修正错误:日期值适用于iPhone,但不适用于iPad,ios,objective-c,iphone,ipad,logging,Ios,Objective C,Iphone,Ipad,Logging,在我的应用程序中,我必须显示一周的日期值。它在iPhone上可以正常工作,但在iPad上不行 1.此图显示iPhone文本框上方的日期值(21…27) 2.此图显示iPad文本框上方错误的日期值(3) 这是我的一段代码: - (void)viewDidLoad { [super viewDidLoad]; // here the self.startday value has been passed from one controller to another. _datelabel.te

在我的应用程序中,我必须显示一周的日期值。它在iPhone上可以正常工作,但在iPad上不行

1.此图显示iPhone文本框上方的日期值(21…27)

2.此图显示iPad文本框上方错误的日期值(3)

这是我的一段代码:

- (void)viewDidLoad 
{
[super viewDidLoad];
// here the self.startday value has been passed from one controller to another.
_datelabel.text = self.startday;
// here the self.startday =@"2016-02-23"
[self method1];
[self getdateArray];
[self method2];
}
我的get date方法代码:

-(void) get date
{
NSString *dateStr,*strday;
NSString *dateFormat=@"yyyy-MM-dd";
NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc] init];
[dateFormatter1 setDateFormat:dateFormat];
NSDate *date = [dateFormatter1 dateFromString:self.startday];
NSLog(@"%@",date);
NSTimeZone *currentTimeZone = [NSTimeZone localTimeZone];
NSTimeZone *utcTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"UTC"];
NSInteger currentGMTOffset = [currentTimeZone secondsFromGMTForDate:date];
NSInteger gmtOffset = [utcTimeZone secondsFromGMTForDate:date];
NSTimeInterval gmtInterval = currentGMTOffset - gmtOffset;
NSDate *destinationDate = [[NSDate alloc] initWithTimeInterval:gmtInterval sinceDate:date];
NSDateFormatter *dateFormatters = [[NSDateFormatter alloc] init];
[dateFormatters setDateFormat:dateFormat];
[dateFormatters setTimeZone:[NSTimeZone systemTimeZone]];
dateStr = [dateFormatters stringFromDate: destinationDate];
self.wkDateArray = [[NSMutableArray alloc] init];
self.wkDayArray = [[NSMutableArray alloc] init];
NSCalendar *calendar = [NSCalendar currentCalendar];
for(int i =0 ;i<7;i++)
{
NSDate *newdate = [destinationDate dateByAddingTimeInterval:60*60*24*i];
NSDateComponents *comp =[calendar components:NSCalendarUnitDay fromDate:newdate];
strday =  [NSString stringWithFormat:@"%ld",[comp day]];
[self.wkDayArray insertObject:strday atIndex:i];
dateStr = [dateFormatters stringFromDate: newdate];
[self.wkDateArray insertObject:dateStr atIndex:i];
}
NSLog(@"%@",self.wkDayArray[0]);
NSLog(@"%@",self.wkDateArray[0]);
} 
如果我将“日期”记录器放在“iPhone目标”中,输出将是:

iphone:2016-02-20 18:30:00 +0000
ipad:(null)
如果我在“iPad目的地”中输入日期记录器,输出将为:

iphone:2016-02-20 18:30:00 +0000
ipad:(null)
然后我得出结论,由于这个空值,设置了一些错误的值


为什么在iPad destination中显示空值?确切的解决方案是什么?提前谢谢。请帮助我。

为iPad和iPhone创建一个新的通用应用程序,只更改以下代码:

- (void)viewDidLoad {
    [super viewDidLoad];

    NSString *startday = @"2016-02-23";
    NSString *dateStr,*strday;
    NSString *dateFormat=@"yyyy-MM-dd";
    NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc] init];
    [dateFormatter1 setDateFormat:dateFormat];
    NSDate *date = [dateFormatter1 dateFromString:startday];
    NSLog(@"%@",date);

}

然后告诉我它是否在两种设备上都有效

iPAd模拟器提供相同的输出?iPAd是否具有相同的时区/位置?第一幅图像是iPhone输出,第二幅图像是iPAd输出。@JonasSchafft我必须检查一下,先生…@DipenChudasama bro我编辑了我的问题,请看一下。给我建议