小编use*_*859的帖子

获取iPhone与iPod Touch时区的最佳做法

我正在创建一个需要用户当前时区的应用.如果正在使用的设备是iPhone并且用户将其时区设置为自动更改,我认为我可以相当确信localTimeZone或systemTimezone将为我提供用户位置的正确时区.

另一方面,如果设备是iPod Touch,则localTimeZone和systemTimeZone返回的时区似乎始终是"日期和时间"设置中设置的任何时区,无论用户的实际位置如何.我尝试使用位置服务,但是,正确提供lat/long时,我得到的timesStamp中的时区偏移量始终与用户为其时区设置设置的值相同.

有什么建议?

约翰

iphone xcode timezone cllocation

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

UISearchBar取消按钮崩溃

我有一个UITableView,在didSelectRowAtIndexPath上推送另一个UITableView进行搜索...

    LocationSearchViewController *locationSearchViewController = [[LocationSearchViewController alloc] initWithNibName:@"LocationSearchViewController"  bundle:nil];
    locationSearchViewController.delegate = self;       
    UITableViewCell *cell = [myTableView cellForRowAtIndexPath:indexPath];
    locationSearchViewController.defaultLocation = cell.detailTextLabel.text;

    [[self navigationController]  pushViewController:locationSearchViewController animated:YES];
    [locationSearchViewController release];
Run Code Online (Sandbox Code Playgroud)

搜索视图包含一个UISearchBar,并启用了取消按钮.如果用户点击取消按钮,应用程序将崩溃并显示objc_exception_throw.控制台显示......

2011-02-06 22:05:43.960 JetLogger [2381:207] *断言失败 - [UISearchDisplayController setActive:animated:],/ SourceCache/UIKit_Sim/UIKit-1447.6.4/UISearchDisplayController.m:589

但是,如果用户点击表格视图中的项目(搜索结果),我将关闭搜索视图,并且没有崩溃.我不明白为什么差异,因为我用相同的代码弹出搜索视图...

在LocationSearchViewController中......

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   if ([self.delegate respondsToSelector:@selector(locationSearchViewDidDismiss:withLocation:)]) {
    [self.delegate locationSearchViewDidDismiss:self withLocation:[tableView cellForRowAtIndexPath:indexPath].textLabel.text];
   }
}
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar{
   if ([self.delegate respondsToSelector:@selector(locationSearchViewDidDismiss:withLocation:)]) {
     [self.delegate locationSearchViewDidDismiss:self withLocation:@"No results found"];
   }
}
Run Code Online (Sandbox Code Playgroud)

在代表......

- (void)locationSearchViewDidDismiss:(LocationSearchViewController *)controller withLocation:(NSString*)location{   
   if((location != @"") && (location != @"No …
Run Code Online (Sandbox Code Playgroud)

iphone user-interface xcode

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

在构建ipa时列出了2个具有相同名称的Ad Hoc Distribution配置文件

这个东西仍然让我困惑.我在开发人员门户中添加了一个设备到我的Ad Hoc配置文件,下载并双击下载的文件.什么都没有出现,所以我进入了xCode 5的组织者,选择了编辑器 - >配置文件 - >导入配置文件.

现在,当我构建我的ipa以进行分发时,配置文件会列出两次.我选择了列表中的第一个,发现它没有新设备,所以我重新编译了构建,选择了第二个,它按预期工作.

我不明白为什么我已经陷入这种情况,也不明白如何删除旧的配置文件.

这是我在xcode中签名的代码.我应该删除并重新开始.如果是的话我会删除哪些?

在此输入图像描述

谢谢,

约翰

xcode provisioning xcode5

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

UISwipeGestureRecognizer无法正常工作

我在UIScrollView中有一个UIView,都是使用IB创建的.UIView在UIScrollView内水平滚动.我想检测左右两根手指滑动.

借用我在SmpleGestureRecognizers中找到的示例代码 ,我将以下代码放在UIScrollView的ViewController的viewDidLoad方法中...

UIGestureRecognizer *recognizer;
UISwipeGestureRecognizer *swipeRightRecognizer, *swipeLeftRecognizer;

recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
swipeRightRecognizer = (UISwipeGestureRecognizer *)recognizer;
swipeRightRecognizer.numberOfTouchesRequired = 2;
[self.view addGestureRecognizer:swipeRightRecognizer];
[recognizer release];

recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
swipeLeftRecognizer = (UISwipeGestureRecognizer *)recognizer;
swipeLeftRecognizer.numberOfTouchesRequired = 2;
swipeLeftRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeLeftRecognizer];
[recognizer release];
Run Code Online (Sandbox Code Playgroud)

我在viewcontroller.h中设置了.并有以下委托方法......

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
   return YES;
}
Run Code Online (Sandbox Code Playgroud)

我假设这是一个有效的gestureRecognizer委托方法,但我在文档中找不到任何对它的引用.

我没有任何错误,但是当我用双指滑动时没有任何反应.不调用委托方法,也不是我的操作方法.我尝试删除numbeOfTouchesRequired调用,看看它是否可以单手滑动无效.

我是否将gestureRecognizers添加到右侧视图中?我尝试将它添加到UIView,UIScrollView以及self.view.superView.

示例代码运行良好.我在代码实现和示例代码之间可以看到的唯一区别是我使用IB创建视图而示例代码没有.我怀疑在它到达我的识别器之前有些东西正在消耗滑动手势.

我究竟做错了什么.

谢谢,

约翰

iphone xcode swipe uigesturerecognizer

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

如何过滤数组字典

我有一个数组字典,我想根据数组中的元素进行过滤.我的字典看起来像这样......

"Abu Dhabi, U.A.E." =     (
    "24.466665",
    "54.416668",
    "Asia/Dubai"
);
"Accra, Ghana" =     (
    "5.583333",
    "-0.100000",
    "Africa/Accra"
);
"Adak, America" =     (
    "",
    "",
    "America/Adak"
);
"Addis Ababa, Ethiopia" =     (
    "9.050000",
    "38.700001",
    "Africa/Addis_Ababa"
);
Run Code Online (Sandbox Code Playgroud)

我想根据第3项过滤字典,例如第三项(时区ID)为"America/Adak"的所有键.

我想我可以用keysOfEntriesPassingTest做到这一点,但我不知道如何做到这一点.我找到了一些示例代码......

mySet = [myDict keysOfEntriesPassingTest:^(id key, id obj, BOOL *stop) {
             if( [[obj port] isEqual: [NSNumber numberWithInt: 8080]]) {
                 return YES;
             else
                 return NO;
             }]
Run Code Online (Sandbox Code Playgroud)

但我无法弄清楚如何重写这个在我的情况下工作.我不明白所需的语法.

有人可以帮我弄清楚如何实现这个过滤器吗?

谢谢,约翰

iphone xcode predicate nsdictionary filter

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

添加到UITableViewCell的UIButton将无法显示

在阅读了这里和其他地方的所有示例之后,我编写了以下代码来向UITableViewCell添加一个按钮,但我无法在单元格中显示它.我究竟做错了什么?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

   static NSString *CellIdentifier = @"Cell";

   UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
   if (cell == nil) {
       cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
   }

UIButton *cellButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[cellButton setFrame:CGRectMake(0.0f, 5.0f, tableView.frame.size.width-2, 44.0f)];
[cellButton setTitle:[aList objectAtIndex:indexPath.row] forState:UIControlStateNormal];
[cell.contentView addSubview:cellButton];
[cellButton release];
return cell;
}   
Run Code Online (Sandbox Code Playgroud)

谢谢,约翰

iphone uibutton uitableview

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