小编Cha*_*lis的帖子

带有多个按钮的导航栏

我有一个带左右按钮的导航栏,我需要在右键旁边放另一个按钮.有谁知道我怎么能这样做?以下是一些有用的代码:

- (id)init {
    self = [super initWithStyle:UITableViewStyleGrouped];
    if (self) {

        _pinArray = [[NSArray alloc]init];
        _pinArray = [Data singleton].annotations;

        UIBarButtonItem *right = [[UIBarButtonItem alloc]initWithTitle:@"Map"
                                                                 style:UIBarButtonItemStylePlain
                                                            target:self
                                                            action:@selector(goToMap:)];
        self.navigationItem.rightBarButtonItem = right;

        UIBarButtonItem *left = [[UIBarButtonItem alloc]initWithTitle:@"Menu"
                                                            style:UIBarButtonItemStylePlain
                                                           target:self
                                                           action:@selector(goToMenu:)];
        self.navigationItem.leftBarButtonItem = left;
        self.navigationItem.title = @"My Homes";
    }
    return self;
}
Run Code Online (Sandbox Code Playgroud)

objective-c uinavigationcontroller uibarbuttonitem ios

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

NSRangeException Out of Bounds错误

我正在设置标签的属性文本,我收到这个奇怪的错误:由于未捕获的异常'NSRangeException'而终止应用程序,原因:'NSMutableRLEArray replaceObjectsInRange:withObject:length :: Out of bounds'.我之前从未见过这个错误,所以我不确定如何修复它.以下是导致崩溃的代码:

if ([cell.waveTextLabel respondsToSelector:@selector(setAttributedText:)])
{
    const CGFloat fontSize = 16.0f;

    //define attributes
    UIFont *boldFont = [UIFont fontWithName:@"HelveticaNeue-Medium" size:fontSize];

    // Create the attributes
    NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys:boldFont, NSFontAttributeName, nil];

    NSRange rangeOfIs = [cell.cellWaveObject.waveString rangeOfString:@" is"];
    NSLog(@"The range of is: {%lu, %lu}", (unsigned long)rangeOfIs.location, (unsigned long)rangeOfIs.length);
    NSRange nameRange = NSMakeRange(0, rangeOfIs.location);
    NSLog(@"The range of the name: {%lu, %lu}", (unsigned long)nameRange.location, (unsigned long)nameRange.length);

    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:cell.cellWaveObject.waveString];
    [attributedString setAttributes:attrs range:nameRange];

    //set the label text
    [cell.waveTextLabel …
Run Code Online (Sandbox Code Playgroud)

nsattributedstring uilabel nsrange nsrangeexception

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

如何左对齐UISearchBar占位符文本

这是设计师希望我创建的搜索栏

我需要像这样制作一个自定义搜索栏.我遇到的问题是左对齐占位符文本,以及将搜索图标放在右侧.我有我试图在使用搜索图标的PNG UIImageView,并设置UIImageViewrightView在的UISearchBarUITextField.这个解决方案没有用,我没有想法.有没有人有办法解决吗?

objective-c uiimageview uisearchbar ios

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

编码CLLocationcoordinate2D

我正在尝试编码地图上的注释,但我读到我无法对CLLocationcoordinate2D变量进行编码.有谁知道我怎么解决这个问题?这是一些代码.

这是我放下引脚的地方:

- (void)press:(UILongPressGestureRecognizer *)recognizer {
    CGPoint touchPoint = [recognizer locationInView:_worldView];
    CLLocationCoordinate2D touchMapCoordinate = [_worldView convertPoint:touchPoint toCoordinateFromView:_worldView];

    geocoder = [[CLGeocoder alloc]init];
    CLLocation *location = [[CLLocation alloc]initWithCoordinate:touchMapCoordinate
                                                    altitude:CLLocationDistanceMax
                                          horizontalAccuracy:kCLLocationAccuracyBest
                                            verticalAccuracy:kCLLocationAccuracyBest
                                                   timestamp:[NSDate date]];
    [geocoder reverseGeocodeLocation:location
               completionHandler:^(NSArray *placemarks, NSError *error) {
                   //NSLog(@"reverseGeocoder:completionHandler: called");
                   if (error) {
                       //NSLog(@"Geocoder failed with error: %@", error);
                   } else {
                       CLPlacemark *place = [placemarks objectAtIndex:0];
                       geocodedAddress = [NSString stringWithFormat:@"%@ %@, %@ %@", [place subThoroughfare], [place thoroughfare], [place locality], [place administrativeArea]];
                       if (UIGestureRecognizerStateBegan == [recognizer state]) {
                           value = …
Run Code Online (Sandbox Code Playgroud)

objective-c nscoding cllocation

10
推荐指数
2
解决办法
4167
查看次数

如何从地址字符串中获取lat和long坐标

我有一个MKMapView,有一个UISearchBar在上面,我希望用户能够键入一个地址,并找到该地址并在其上放置一个图钉.我不知道的是如何将地址字符串转换为经度和纬度,所以我可以创建一个CLLocation对象.有谁知道我怎么做到这一点?

mapkit cllocation cllocationcoordinate2d

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

如何对NSString进行URL编码

我试图url编码一个字符串,但NSURLConnection失败,因为'坏网址'.这是我的网址:

    NSString *address = mp.streetAddress;
    NSString *encodedAddress = [address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSString *cityState= mp.cityState;
    NSString *encodedCityState = [cityState stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    NSString *fullAddressURL = [NSString stringWithFormat:@"http://www.zillow.com/webservice/GetDeepSearchResults.htm?zws-id=<X1-ZWz1bivd5de5mz_8xo7s>&address=%@&citystatezip=%@", encodedAddress, encodedCityState];
    NSURL *url = [NSURL URLWithString:fullAddressURL];
Run Code Online (Sandbox Code Playgroud)

以下是API调用URL的示例:

下面是调用API的地址匹配"2114 Bigelow Ave","Seattle,WA"的地址的示例:

http://www.zillow.com/webservice/GetDeepSearchResults.htm?zws-id=<ZWSID>&address=2114+Bigelow+Ave&citystatezip=Seattle%2C+WA
Run Code Online (Sandbox Code Playgroud)

由于某种原因,此URL无法连接.有人可以帮我吗?

encoding nsurl nsstring

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

UIKit.h 未找到错误

我为 ipad 制作了一个单视图应用程序,带有电影、网页视图和按钮,当我尝试运行它时出现此错误。我重新启动了应用程序,并重新安装了它,但没有任何效果。这个错误不断出现在我的 MoviePlayer_Prefix.pch 文件中。有人可以帮我吗?

objective-c uikit ipad

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

将UIScrollView的底部淡入透明

我有一个UIScrollView,我需要将底部淡入淡出,以便它不会突然切断内容.UIScrollView的背景是自定义颜色.这是我到目前为止,但图层显示为白色,而不是自定义颜色.这就是我想要的,但仅限于底层.

:这就是我想要的,但仅限于底层

这是我到目前为止:

maskLayer = [CAGradientLayer layer];

            CGColorRef firstColor = [UIColor colorWithRed:141 green:211 blue:244 alpha:1.0].CGColor;
            CGColorRef secondColor = [UIColor colorWithRed:141 green:211 blue:244 alpha:0.8].CGColor;
            CGColorRef thirdColor = [UIColor colorWithRed:141 green:211 blue:244 alpha:0.2].CGColor;
            CGColorRef fourthColor = [UIColor colorWithRed:141 green:211 blue:244 alpha:0.0].CGColor;

            maskLayer.colors = [NSArray arrayWithObjects:(__bridge id)firstColor, (__bridge id)secondColor, (__bridge id)thirdColor, (__bridge id)fourthColor, nil];
            maskLayer.locations = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0],
                                                        [NSNumber numberWithFloat:0.2],
                                                        [NSNumber numberWithFloat:0.8],
                                                        [NSNumber numberWithFloat:1.0], nil];
            maskLayer.frame = CGRectMake(0, 285, self.loginScrollView.frame.size.width, 40);
            maskLayer.anchorPoint = CGPointZero;
            [self.loginScrollView.layer addSublayer:maskLayer];
Run Code Online (Sandbox Code Playgroud)

由于某种原因,图层显示为白色,只有scrollView的一半宽度.

calayer uiscrollview

6
推荐指数
3
解决办法
6638
查看次数

UIBezierPath不使用applyTransform方法旋转

我正在创建3个矩形UIBezierPath,我想旋转45度.我使用applyTransform方法并通过CGAffineTransformMakeRotation.我已经遍布谷歌了,而且我所做的任何实现都没有.有谁看到我做错了什么?这是我的代码:

#define DEGREES_TO_RADIANS(x) (M_PI * (x) / 180.0)

@implementation BaseballDiamondView

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    CGRect superViewFrame = self.bounds;
    [[UIColor whiteColor] setFill];

    // draw third base
    UIBezierPath *thirdBasePath = [UIBezierPath bezierPathWithRect:CGRectMake(2.0, 4.0, 7.0, 7.0)];
    [thirdBasePath fill];

    // draw second base
    UIBezierPath *secondBasePath = [UIBezierPath bezierPathWithRect:CGRectMake((superViewFrame.size.width / 2.0) - 3.0, 2.0, 7.0, 7.0)];
    [secondBasePath fill];

    // draw first base …
Run Code Online (Sandbox Code Playgroud)

objective-c cgaffinetransform ios uibezierpath

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

如何在objective-c中解析ISO 8601日期

我需要从json创建一个NSDate,并以我从未使用过的格式创建日期.我要回来的日期字符串是2014-02-07T03:10:43.824Z.有谁知道我需要用于日期格式化程序的正确日期格式字符串?

iso objective-c nsdate

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

TableView backgroundColor没有改变

我有一个分组tableView,我试图将默认背景更改为自定义颜色.我看了一遍,最接近工作的是:

- (void)viewDidLoad {
    UIColor *backgroundColor = [UIColor colorWithRed:181 green:293 blue:223 alpha:0];
    self.tableView.backgroundView = [[UIView alloc]initWithFrame:self.tableView.bounds];
    self.tableView.backgroundView.backgroundColor = backgroundColor;
}
Run Code Online (Sandbox Code Playgroud)

此代码将背景更改为白色,但我无法将其更改为自定义颜色.有人可以帮我吗?

objective-c background-color uitableview

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

将我的应用程序与Zillow API集成

我需要将我的应用程序与Zillow API集成,以检索要显示的特定信息.

我不知道这样做,所以我需要一些关于如何解决这个问题的一般信息.

api ios

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

isEqualToString:没有正确比较字符串

我有两个完全相同的字符串,但它们没有被比较为相等.一个字符串是一个可变字符串,另一个是普通字符串,我有一个if语句来检查两个字符串是否相等.两个字符串的输出是这样的:

2013-04-08 09:09:31.555 Pin2Own[650:1303] 6447 E Crocus Dr
2013-04-08 09:09:31.555 Pin2Own[650:1303] 6447 E Crocus Dr
Run Code Online (Sandbox Code Playgroud)

顶部是可变字符串,底部是普通字符串.我已经尝试将可变字符串转换为普通字符串,但我遇到了同样的问题.我从NSXMLParser子类中的xml文档获取可变字符串,另一个从单例中的可变数组中获取.以下是NSXMLParser类的代码:

- (void)parserDidStartDocument:(NSXMLParser *)parser
{
    address = nil;
    zpid = nil;
}

- (void)parser:(NSXMLParser *)parser
didStartElement:(NSString *)elementName
  namespaceURI:(NSString *)namespaceURI
 qualifiedName:(NSString *)qualifiedName
    attributes:(NSDictionary *)attributeDict
{
    if ([elementName isEqualToString:@"street"])
    address = [[NSMutableString alloc] init];

    if ([elementName isEqualToString:@"zpid"])
    zpid = [[NSMutableString alloc] init];
}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
    if(address)
    [address setString:string];

    else if(zpid)
    [zpid setString:string];
}

- (void)parser:(NSXMLParser *)parser
 didEndElement:(NSString *)elementName
  namespaceURI:(NSString *)namespaceURI
 qualifiedName:(NSString *)qName
{ …
Run Code Online (Sandbox Code Playgroud)

compare nsstring ios

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