Obj*_*ift 4 cocoa-touch objective-c clang-static-analyzer ios
我第一次使用静态分析仪,很难弄清楚箭头.在看了一些关于SO的类似问题后,我认为问题是CGSize大小是零值,但我不完全确定它是如何工作的.
这是代码:
- (void)keyboardDidShow:(NSNotification*)notification {
CGSize size = CGSizeMake(0, 0);
size = [self keyboardSize:notification];
if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) {
detailTableView.frame = CGRectMake(detailTableView.frame.origin.x, detailTableView.frame.origin.y,
detailTableView.frame.size.width, kTableViewMovableHeight + kTableViewDefaultHeight - size.height
);
//detailTableView.scrollEnabled = YES;
}
}
- (CGSize)keyboardSize:(NSNotification *)aNotification {
NSDictionary *info = [aNotification userInfo];
NSValue *beginValue = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
CGSize keyboardSize;
UIDeviceOrientation _screenOrientation = orientation;
if ([UIKeyboardDidShowNotification isEqualToString:[aNotification name]]) {
if (UIDeviceOrientationIsPortrait(orientation)) {
keyboardSize = [beginValue CGRectValue].size;
} else {
keyboardSize.height = [beginValue CGRectValue].size.width;
keyboardSize.width = [beginValue CGRectValue].size.height;
}
} else if ([UIKeyboardWillHideNotification isEqualToString:[aNotification name]]) {
if (_screenOrientation == orientation) {
if (UIDeviceOrientationIsPortrait(orientation)) {
keyboardSize = [beginValue CGRectValue].size;
} else {
keyboardSize.height = [beginValue CGRectValue].size.width;
keyboardSize.width = [beginValue CGRectValue].size.height;
}
// rotated
} else if (UIDeviceOrientationIsPortrait(orientation)) {
keyboardSize.height = [beginValue CGRectValue].size.width;
keyboardSize.width = [beginValue CGRectValue].size.height;
} else {
keyboardSize = [beginValue CGRectValue].size;
}
}
return keyboardSize;
}
Run Code Online (Sandbox Code Playgroud)

[self keyboardSize:notification] 可能会返回零声明C结构时,其值具有垃圾值.也就是说,之前的那段记忆中的任何东西.如果你的调用keyboardSize返回一个未初始化的CGSize,那个C结构将具有所谓的"垃圾值".
现在我看到了CGSize的实现,将keyboardSize方法中变量keyboardSize的声明更改为:
CGSize keyboardSize = CGSizeMake(0, 0);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2465 次 |
| 最近记录: |