小编Bra*_*don的帖子

从appDelegate中的locationManager传递坐标到viewController

我想在viewController出现时获取用户的坐标.我需要几个viewControllers中的位置,所以我将locationManager放在appDelegate中.我的问题是,在第一个viewDidAppear上,尚未找到坐标.我该怎么做才能改变这个?谢谢你们!!!

我的AppDelegate有这个:

- (NSString *)getUserCoordinates
{
NSString *userCoordinates = [NSString stringWithFormat:@"latitude: %f longitude: %f", 
locationManager.location.coordinate.latitude,     locationManager.location.coordinate.longitude];
locationManager = [[CLLocationManager alloc] init];
locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
[locationManager startUpdatingLocation];
return userCoordinates;
}
Run Code Online (Sandbox Code Playgroud)

我的viewController获取坐标:

- (void)viewDidAppear 
{
NSString *userCoordinates =[(PDCAppDelegate *)[UIApplication sharedApplication].delegate 
getUserCoordinates];
}
Run Code Online (Sandbox Code Playgroud)

iphone xcode core-location locationmanager ios

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

通过MKAnnotation CalloutAccessoryControlTapped传递自定义属性

我正在尝试执行通过MKAnnotation传递自定义属性(placeId)的简单功能.我已经使用名为"MapViewAnnotation"的自定义类设置了所有内容.

当用户激活CalloutAccessoryControlTapped时,我想简单地将一个额外的值从MapViewController传递给DetailViewController.我可以让标题/副标题起作用,但我需要修改我的代码以允许自定义变量.

我已经尝试了一段时间,但无法让它正常工作.任何帮助都会很棒!谢谢!

MapViewAnnotation.h

@interface MapViewAnnotation : NSObject <MKAnnotation> {
    NSString *title;
    CLLocationCoordinate2D coordinate;
}

@property (nonatomic, copy) NSString *title;
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *subtitle;

- (id)initWithTitle:(NSString *)ttl andCoordinate:(CLLocationCoordinate2D)c2d;

@end
Run Code Online (Sandbox Code Playgroud)

MapViewAnnotation.m

@implementation MapViewAnnotation

@synthesize title, coordinate, subtitle;

- (id)initWithTitle:(NSString *)ttl andCoordinate:(CLLocationCoordinate2D)c2d {
    title = ttl;
    coordinate = c2d;
    subtitle = @"Test Subtitle";
    return self;
}

@end
Run Code Online (Sandbox Code Playgroud)

MapViewController.m中的注释创建 - 在这里你可以看到我正在使用副标题来传递placeId(底线)

location.latitude = [dictionary[@"placeLatitude"] doubleValue];
location.longitude = [dictionary[@"placeLongitude"] doubleValue];    

newAnnotation = [[MapViewAnnotation alloc] initWithTitle:dictionary[@"placeName"]
                                               andCoordinate:location];

newAnnotation.subtitle = …
Run Code Online (Sandbox Code Playgroud)

objective-c mapkit mkmapview mkannotation ios

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

自动选择第一个UITableView文本框

我有一个接受登录凭据的tableview.我希望我的应用程序在加载或显示时自动选​​择第一个tableview文本框.我希望将光标放在"电子邮件地址"字段中,并自动引发键盘.我似乎无法弄清楚这一点.有人有主意吗?谢谢!

在此输入图像描述

iphone objective-c uitableview ios

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

使用CLGeocoder将NSString Latiude/Longitude Coordinates转换为City,State和Timezone

我有一个视图控制器,从应用程序委托中提取用户的纬度和经度坐标.这很好用,但我还需要用户的城市,州和时区.我知道我应该使用CLGeocoder(请参阅最后一块代码),但不知道如何将它放在一起.我只需要城市,州和时区的NSStrings.任何人有任何指针或一个例子?谢谢!

在我的App Delegate中,我使用CCLocationManager来获取这样的坐标:

- (NSString *)getUserCoordinates
{
    NSString *userCoordinates = [NSString stringWithFormat:@"latitude: %f longitude: %f", 
    locationManager.location.coordinate.latitude, 
    locationManager.location.coordinate.longitude];
    locationManager = [[CLLocationManager alloc] init];
    locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
    locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
    [locationManager startUpdatingLocation];
    return userCoordinates;
}

- (NSString *)getUserLatitude
{
    NSString *userLatitude = [NSString stringWithFormat:@"%f", 
    locationManager.location.coordinate.latitude];
    return userLatitude;
}

- (NSString *)getUserLongitude
{
    NSString *userLongitude = [NSString stringWithFormat:@"%f", 
    locationManager.location.coordinate.longitude];
    return userLongitude;
}
Run Code Online (Sandbox Code Playgroud)

在我的View Controller中,我将用户的纬度和经度作为NSString获取:

NSString *userLatitude =[(PDCAppDelegate *)[UIApplication sharedApplication].delegate 
getUserLatitude];

NSString *userLongitude =[(PDCAppDelegate *)[UIApplication sharedApplication].delegate 
getUserLongitude]; …
Run Code Online (Sandbox Code Playgroud)

iphone xcode objective-c ios

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

活动指示器周围的圆形框与"加载"文本

我知道如何使用简单的方形背景制作活动指示器,但根本没有填充,我不知道如何将"加载"这个词显示为这样.

在此输入图像描述

有谁知道这是如何实现的?我看过网上似乎找不到任何东西.谢谢你们!

objective-c uiviewcontroller uiactivityindicatorview ios

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

与整数转换不兼容的指针将'void*'发送到'NSJSONReadingOptions'类型的参数

我收到一个奇怪的编译器警告.它说:

Incompatible pointer to integer conversion sending 'void *' to parameter of type 
'NSJSONReadingOptions' (aka 'enum NSJSONReadingOptions') 
Run Code Online (Sandbox Code Playgroud)

这是它的块:

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

    //Incompatible pointer to integer conversion sending 'void *' to parameter of type 
    'NSJSONReadingOptions' (aka 'enum NSJSONReadingOptions')

    news = [NSJSONSerialization JSONObjectWithData:data options:nil error:nil];
    [mainTableView reloadData];
}
Run Code Online (Sandbox Code Playgroud)

任何想法如何解决这一问题?谢谢!

iphone xcode objective-c ios

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

使用Strtotime格式化小时,分钟和上午/下午的变量

我试图弄清楚如何使用strtotime与下面的值.我认为这应该很简单,但我无法得到它.我希望输出类似于:

日期("H:i:s") - 看起来像是 - 16:30:00

<?php

$hour = "4";
$minute = "30";
$period = "PM";

echo strtotime("$hour $minute $period")

?>
Run Code Online (Sandbox Code Playgroud)

我一直在挖掘一段时间,但无法弄清楚这一点.任何想法都会非常有用!谢谢!

php strtotime

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

将NSString解析为JSON

我已经阅读了几个论坛,但我似乎无法完成这个简单的任务.我在Xcode中有一个View,它指向一个PHP脚本并将结果存储为下面的NSString:

[{ "ID": "16", "名称": "鲍勃", "年龄": "37"}]

我在解析此NSString时遇到问题.这是我获取NSString的内容的方式:

NSString *strURL = [NSString stringWithFormat:@"http://www.website.com/json.php?
id=%@",userId];

// to execute php code
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];

// to receive the returend value
NSString *strResult = [[NSString alloc] initWithData:dataURL 
encoding:NSUTF8StringEncoding];
Run Code Online (Sandbox Code Playgroud)

如何将结果(strResult)转换为JSON并从中取出对象?我会假设下面的东西,但我知道我错过了一些东西

NSString *name = [objectForKey:@"name"];
NSString *age = [objectForKey:@"age"];
Run Code Online (Sandbox Code Playgroud)

任何帮助都会很棒.谢谢!

php iphone parsing json objective-c

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

当App来到前台时,调用self.viewDidAppear

当用户将应用程序带到前台时,我想让我的应用程序再次调用viewDidAppear.

- (void)appReturnsActive{

    //THIS IS THE BIT THAT DOESNT WORK, BUT [self.viewDidLoad] DOES WORK
    [self.viewDidAppear];
}
Run Code Online (Sandbox Code Playgroud)

我正在我的viewDidAppear方法中创建appReturnsActive.效果很好:

[[NSNotificationCenter defaultCenter] addObserver:self 
selector:@selector(appReturnsActive) name:UIApplicationDidBecomeActiveNotification 
object:nil];
Run Code Online (Sandbox Code Playgroud)

我可以做self.viewDidLoad,但我不能选择viewDidAppear.有谁知道我怎么可能让这个工作?

谢谢!!

iphone xcode objective-c ios

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

本地声明隐藏实例变量 - tableView未合成

我已经读过使用下划线来修复编译器警告,说明"本地声明隐藏实例变量",但我无法实现修复.我读过的解决方案说在我的.h文件中使用下划线,在我的.m文件中使用@synthesize部分.但是,我没有合成我的tableView.请参阅下面的头文件:

.h文件

@interface ListViewController : GAITrackedViewController <UISearchDisplayDelegate, 
UISearchBarDelegate, UITableViewDataSource, UITableViewDelegate> {

IBOutlet UITableView *tableView;

}
Run Code Online (Sandbox Code Playgroud)

.m文件

//SYNTHESIZE
@synthesize listItems, filteredListItems, savedSearchTerm, savedScopeButtonIndex, 
searchWasActive, mapView, loadingImageView, loadingActivity;



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

 //FIRST WARNING for tableView HERE

if (tableView == self.searchDisplayController.searchResultsTableView){
    return [self.filteredListItems count];
    }
    else{
        return [self.listItems count];
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    //SECOND WARNING for tableView HERE

    [tableView setRowHeight: 60.00];
    return 1;

}
Run Code Online (Sandbox Code Playgroud)

iphone xcode objective-c ios

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