小编Spe*_*efy的帖子

删除自定义标签栏上的行

我制作了一个自定义标签栏,其中一个延伸到栏外.有一条线与中心标签栏重叠.无论如何我可以摆脱这个或隐藏吗?

在此输入图像描述

要做到这一点,我只需设置标签栏图像:

 UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UITabBar *tabBar = tabBarController.tabBar;
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1];
UITabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:2];


tabBarItem1.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
tabBarItem3.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);

[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"scheduleTabBarImageSel.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"scheduleTabBarImage.png"]];
   [tabBarItem3 setFinishedSelectedImage:[UIImage imageNamed:@"favoritesTabBarImageSel.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"favoritesTabBarImage.png"]];
[tabBarItem2 setFinishedSelectedImage:[UIImage imageNamed:@"searchTabBarImageSel.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"searchTabBarImage.png"]];
Run Code Online (Sandbox Code Playgroud)

知道如何隐藏线路吗?谢谢

customization objective-c line uitabbar ios

7
推荐指数
2
解决办法
2589
查看次数

如何在cellforrowatindexpath之后更新自定义表格单元格中的UIButton图像?

我的桌面视图中有一个按钮,在点击后会发生变化.

在我的cellforrowatindexpath中,我有

 [cell.graphicButton addTarget:self action:@selector(changeGraphic:)forControlEvents:UIControlEventTouchUpInside];
Run Code Online (Sandbox Code Playgroud)

应该调用changeGraphic(更改图形).调用成功,但在changeGraphic中,图像不会改变.

- (IBAction)changeGraphic:sender
{


    buttonState++;
// button state is an int, im not using BOOl because I have more than 2 images to change from, but for this question i only included 2
    if(buttonState == 2){
        buttonState = 0;
    }
    // 1 = travel time 2 =activity time 3 = total time
    if (buttonState == 0) {



         [cell.vicinitimeGraphicButton setBackgroundImage:[UIImage imageNamed:@"travelDistanceGraphicGreen.png"] forState:UIControlStateNormal];
    }

    if (buttonState == 1) {


         [cell.vicinitimeGraphicButton setBackgroundImage:[UIImage imageNamed:@"activityTimeGraphicGreen.png" ] forState:UIControlStateNormal];
    }

[self.tableView beginUpdates]; …
Run Code Online (Sandbox Code Playgroud)

image uibutton uitableview didselectrowatindexpath ios

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

NSJSONSerialization在iOS中为MapQuest JSON返回null

我试图在iOS中解析mapquest地理编码json,但NSJSONSterilization返回null.我检查了在线json检查器,看起来网址实际上是一个json.

这是代码 NSJSONSerialization

 if(geocodeResponseData)
 {
     NSLog(@"there is response data");
     //this is logged.
 }


 NSDictionary *mapQuestReponse =  [NSJSONSerialization
                                     JSONObjectWithData:geocodeResponseData
                                     options:kNilOptions
                                     error:&error];

 NSLog(@"mapquestreponse %@", mapQuestReponse);
Run Code Online (Sandbox Code Playgroud)

这是JSON为解析而返回的URL.

http://www.mapquestapi.com/geocoding/v1/batch?key=API----KEY----HIDDEN----&callback=renderBatch&outFormat=json&location=14443%20C%20Big%20Basin%20Way,Saratoga,%20CA%2095070&location=14510%20Big%20Basin%20Way,Saratoga,%20CA%2095070&location=14550%20Big%20Basin%20Way,Saratoga,%20CA%2095070&location=14515%20Big%20Basin%20Way,Saratoga,%20CA%2095070&location=1480%20S%20De%20Anza%20Blvd,San%20Jose,%20CA%2095129&location=1600%20S%20De%20Anza%20Blvd,San%20Jose,%20CA%2095129&location=18486%20Prospect%20Rd,San%20Jose,%20CA%2095070&location=14572%20Big%20Basin%20Way,Saratoga,%20CA%2095070&location=5210%20Prospect%20Rd,San%20Jose,%20CA%2095129&location=1600%20S%20De%20Anza%20Blvd,San%20Jose,%20CA%2095106&location=14480%20Big%20Basin%20Way,Saratoga,%20CA%2095070&location=1818%20Saratoga%20Ave,San%20Jose,%20CA%2095129&location=18562%20Prospect%20Rd,Saratoga,%20CA%2095070&location=14560%20Big%20Basin%20Way,Saratoga,%20CA%2095070&location=14420%20Big%20Basin%20Way,Saratoga,%20CA%2095070&location=1075%20S%20De%20Anza%20Blvd,Cupertino,%20CA%2095129&location=18802%20Cox%20Ave,Saratoga,%20CA%2095070&location=6154%20Bollinger%20Rd,San%20Jose,%20CA%2095129&location=14555%20Big%20Basin%20Way,Saratoga,%20CA%2095070&location=14000%20Fruitvale%20Ave,Saratoga,%20CA%2095070
Run Code Online (Sandbox Code Playgroud)

是因为回来NULLutf-8吗?提前致谢

null parsing ios mapquest nsjsonserialization

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

将UIImage添加到数组时无法识别的选择器错误

我存储UIImage在一个NSDictionary,然后使NSDictionary在应用中的另一个地方.gridImages是一个NSMutableArray

NSDictionary *pageDict = [pageArray objectAtIndex:0];

UIImage *pageImage = [pageDict objectForKey:@"image"];

[gridImages addObject:pageImage];
Run Code Online (Sandbox Code Playgroud)

pagedict返回

{
    class = is;
    image = "<UIImage: 0x14e20e10>";
    name = kaka;
    page = 64;
}
Run Code Online (Sandbox Code Playgroud)

这大概是我做的

UIImage *pageImage = [pageDict objectForKey:@"image"];
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试将UIImage添加到数组时,我收到此错误:

-[UIImage stringByDeletingPathExtension]: unrecognized selector sent to instance 0x14e20e10
Run Code Online (Sandbox Code Playgroud)

有什么想法吗?

编辑:

对于NSDictionary,我尝试存储UIImageas NSData:

NSData *imageData = UIImagePNGRepresentation(textbookImage);
    [pageDict setObject:imageData forKey:@"image"];
    [pageDict setObject:textbookName forKey:@"name"];
    [pageDict setObject:page forKey:@"page"];
    [pageDict setObject:nameOfClass forKey:@"class"];
Run Code Online (Sandbox Code Playgroud)

并解析它像这样:

  NSData *imageData = …
Run Code Online (Sandbox Code Playgroud)

objective-c nsdictionary uiimage nsarray ios

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

UICollectionViewCell Selection每5个单元格选择/突出显示

我有一个水平的集合视图,其代码用于突出显示/为所选单元格着色.它突出显示所选的单元格,但之后每5个单元格也会突出显示.知道发生了什么事吗?

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    for(int x = 0; x < [cellArray count]; x++){
        UICollectionViewCell *UnSelectedCell = [cellArray objectAtIndex:x];
        UnSelectedCell.backgroundColor = [UIColor colorWithRed:0.2 green:0.5 blue:0.8 alpha:0.0];
    }
    UICollectionViewCell *SelectedCell = [cellArray objectAtIndex:indexPath.row];
    SelectedCell.backgroundColor = [UIColor colorWithRed:0.2 green:0.5 blue:0.8 alpha:1.0];
    cellSelected = indexPath.row;
    NSLog(@"%i", cellSelected);

}
Run Code Online (Sandbox Code Playgroud)

xcode objective-c ios uicollectionview uicollectionviewcell

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

即使在主线程上运行,也不会调用NSURLConnection委托

我知道这个问题已被多次提出,但所有这些问题都指出连接必须在不同的线程上.

-(void)distanceMatrix{

  NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:distanceMatrixURL]
                                                       cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                   timeoutInterval:10];

connection2 = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:NO];

[connection2 scheduleInRunLoop:[NSRunLoop mainRunLoop]
                      forMode:NSDefaultRunLoopMode];

NSLog(@"Is%@ main thread", ([NSThread isMainThread] ? @"" : @" NOT"));
[connection2 start];

if (connection2)
{
    responseData2 = [NSMutableData data];
    connectionIsActive = YES;    
} else {
    NSLog(@"connection failed");
}
}

- (void)connection2:(NSURLConnection *)connection2 didReceiveResponse:(NSURLResponse *)response
{NSLog(@"recieved response");
[responseData2 setLength:0];

}

- (void)connection2:(NSURLConnection *)connection2 didReceiveData:(NSData *)data
{
[responseData2 appendData:data];

}

- (void)connection2:(NSURLConnection *)connection2 didFailWithError:(NSError *)error
{
connectionIsActive = NO;
    NSLog(@"failed!!");
} …
Run Code Online (Sandbox Code Playgroud)

xcode delegates objective-c nsurlconnection

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

当键盘出现时,将UITextField和UITableView向上移动

我有一个视图1.导航栏2.UITableView 3. UITextView.

当我开始编辑textView时,会出现一个键盘,我需要为TextView和TableView设置动画.我已经实现了:https://stackoverflow.com/a/8704371/1808179,但这会动画整个视图,覆盖导航栏.

我尝试单独动画textView,如:

- (void)keyboardWillShow:(NSNotification*)notification
{
    CGRect chatTextFieldFrame = CGRectMake(chatTextField.frame.origin.x,chatTextField.frame.origin.y-218,chatTextField.frame.size.width,chatTextField.frame.size.height);
    [UIView animateWithDuration:0.5 animations:^{ chatTextField.frame = chatTextFieldFrame;}];
}
Run Code Online (Sandbox Code Playgroud)

但它没有动画,也不会与TableView同步动画.

在不覆盖导航栏的情况下,为tableView和textView设置动画的最佳方法是什么?

objective-c uinavigationbar uitableview uitextfield ios

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

关闭模态,然后立即推视图控制器

如何解除模态然后立即推送另一个视图?

我在didSelectRowAtIndexPath中添加此代码:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
ChatTableViewController *chatVC = (ChatTableViewController*)[storyboard instantiateViewControllerWithIdentifier:@"chatVC"];
 [self dismissViewControllerAnimated:YES completion:^{
    [[self navigationController] pushViewController:chatVC animated:YES];
}];
Run Code Online (Sandbox Code Playgroud)

模态视图解散,但之后没有任何反应.有任何想法吗?

objective-c storyboard ios segue

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