iOS 项目中常见问题及解决办法

最近做项目遇到一些小问题,虽然不严重但是也是必须要清楚how to finish的,如:


键盘管理,与tableView结合使用,聊天界面的键盘管理

#pragma mark - 监听键盘高度改变事件
- (void)keyboardWillShow:(NSNotification *)notification {
    // get keyboard frame
    CGRect frameOfKeyboard = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    UIView * window = [[[UIApplication sharedApplication] delegate] window];
    frameOfKeyboard = [self.view convertRect:frameOfKeyboard fromView:window];
    
    CGRect frameOfInputView = self.toolBar.frame;
    frameOfInputView.origin.y = frameOfKeyboard.origin.y - frameOfInputView.size.height;
    
    UIEdgeInsets insets = UIEdgeInsetsZero;
    insets.bottom = frameOfKeyboard.size.height;
    
    // get infomation of keyboard animation
    NSTimeInterval duration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    UIViewAnimationOptions options = [notification.userInfo[UIKeyboardAnimationCurveUserInfoKey] unsignedIntegerValue];
    [UIView animateWithDuration:duration
                          delay:0
                        options:options
                     animations:^{
                         self.toolBar.frame       = frameOfInputView;
                         self.chatTableView.contentInset = insets;
                     } completion:nil];
    
    [self scrollToBottom];
    //self.isInputPadShow = YES;
    [self.chooseImage setHidden:YES];
    self.isKeyboardShow = YES;
}
-(void)scrollToBottom{
    if (self.sumChat.count > 0) {
        NSIndexPath *path = [NSIndexPath indexPathForRow:self.sumChat.count-1
                                               inSection:0];
        [self.chatTableView scrollToRowAtIndexPath:path
                                  atScrollPosition:UITableViewScrollPositionBottom
                                          animated:YES];
    }
}



给聊天信息背景切图的时候,总是切不出想要的效果来,最后发现原来是@2x的背景图,用的时候直接把图片名包括@2x都写进来了,去掉@2x 即可

UIImage* trackImage = [UIImage imageNamed:@"icon_audio_gray_img.png"];
        trackImage = [trackImage resizableImageWithCapInsets:UIEdgeInsetsMake(2, 12, 2, 2)
                                      resizingMode:UIImageResizingModeStretch];


在代码中给控件设置文字颜色或背景颜色时  使用

[UIColor colorWithRed: green: blue:];
这个方法,如果直接写255 之类的值显示的效果肯定不是我们想要的,或者无法显示,此时应该是用rgb的值除以255,如119.0/255 ,注意是浮点型

如何让UIButton的title左对齐,


【iOS开发】判断NSString中的字符是否为中文的正确方法
在Unicode编码的NSString中,遍历字符串中的汉字呢

unichar ch = [string characterAtIndex:i];
if (0x4e00 < ch  && ch < 0x9fff)
{
    return true;
}

这样的确可以判断大多数中文符号,但是少数字符比如句号“。”
在unichar存储的16进制值要小于0x4e00,查了很多资料
#define IS_CH_SYMBOL(chr) ((int)(chr)>127)


NSMutableDictionary * params = [NSMutableDictionary dictionary];
             [params setObject:self.firstNameLabel.text forKey:@"firstName"];
             [params setObject:self.lastNameLabel.text forKey:@"lastName"];
             [params setObject:self.telLabel.text forKey:@"phoneNum"];
             [params setObject:self.emailLabel.text forKey:@"email"];
             [params setObject:self.feedbackContent.text forKey:@"commons"];
             NSString * postURL = [params cdvjk_JSONString];
             NSLog(@"postURL:%@",postURL);
             NSString * urlStr = FEEDBACK;
             NSLog(@"url%@",urlStr);
             NSURL * url = [NSURL URLWithString:urlStr];
             NSMutableURLRequest * request = [[NSMutableURLRequest alloc] initWithURL:url];
             [request setHTTPMethod:@"POST"];
             [request setHTTPBody:[postURL dataUsingEncoding:NSUTF8StringEncoding]];
             [request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
             
             NSURLResponse * urlResponse = [[NSURLResponse alloc] init];
             NSError * error = nil;
             NSData * data = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
             
             NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值