您的位置:首页 > 移动开发 > IOS开发

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

2014-07-17 00:16 162 查看
最近做项目遇到一些小问题,虽然不严重但是也是必须要清楚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];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  uibutton ios