小编Nij*_*018的帖子

如何以编程方式更改或更新NSLayoutConstraint

我已使用代码以编程方式实现了AutoLayout:

- (void)addConstraintWithListNavigationViewController:(UIView *)listViewNavigation y:(CGFloat)y height:(CGFloat)height
{
    //WIDTH_ListTableView = 0.4

    //set x = 0;
    NSLayoutConstraint *constraintToAnimate1 = [NSLayoutConstraint constraintWithItem:listViewNavigation
                                                                            attribute:NSLayoutAttributeLeft
                                                                            relatedBy:NSLayoutRelationEqual
                                                                               toItem:self.view
                                                                            attribute:NSLayoutAttributeLeft
                                                                           multiplier:0.00
                                                                             constant:0];
    [self.view addConstraint:constraintToAnimate1];


    //set y = y;
    NSLayoutConstraint *constraintToAnimate2 = [NSLayoutConstraint constraintWithItem:listViewNavigation
                                                                            attribute:NSLayoutAttributeTop
                                                                            relatedBy:NSLayoutRelationEqual
                                                                               toItem:self.view
                                                                            attribute:NSLayoutAttributeBottom
                                                                           multiplier:0.00
                                                                             constant:y];
    [self.view addConstraint:constraintToAnimate2];








    //set Width = self.view.frame.size.width*0.4
    NSLayoutConstraint *constraintToAnimate3 = [NSLayoutConstraint constraintWithItem:listViewNavigation
                                                                            attribute:NSLayoutAttributeWidth
                                                                            relatedBy:NSLayoutRelationEqual
                                                                               toItem:self.view
                                                                            attribute:NSLayoutAttributeWidth
                                                                           multiplier:1-WIDTH_ListTableView
                                                                             constant:0.0];
    [self.view addConstraint:constraintToAnimate3];





    //Set height = height
    NSLayoutConstraint *constraintToAnimate4 = [NSLayoutConstraint constraintWithItem:listViewNavigation
                                                                            attribute:NSLayoutAttributeHeight
                                                                            relatedBy:NSLayoutRelationEqual
                                                                               toItem:nil
                                                                            attribute:NSLayoutAttributeNotAnAttribute
                                                                           multiplier:0.00
                                                                             constant:height];
    [self.view addConstraint:constraintToAnimate4];
}
Run Code Online (Sandbox Code Playgroud)

这很完美,但每次这个ViewController收到一个 …

objective-c ios nslayoutconstraint

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

Xcode - 我的应用程序崩溃,错误是"从无效列表中退出的无效指针***在malloc_error_break中设置断点以进行调试"

我的应用在模拟器上运行完美.但是当我在设备上运行它时,应用程序崩溃并显示错误:

"malloc:*对象错误0x17415d0c0:无效指针从空闲列表中出列*在malloc_error_break中设置断点以进行调试";

我搜索并设置了一个断点malloc_error_break来调试,但仍然找不到问题.我试图改变项目方案,启用Zombie Object,但找不到答案.

我也尝试使用乐器,但我不擅长.

memory malloc xcode ios

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

Xcode:检测到堆损坏,自由列表金丝雀已损坏

我运行应用程序后出现这种错误,有时我有这个错误,有时候没有.

AppName(2794,0x195bf72a0)malloc:*对象0x170143860的错误:检测到堆损坏,空闲列表金丝雀损坏*在malloc_error_break中设置断点以进行调试

有人可以帮帮我,谢谢.

memory objective-c ios xcode6

5
推荐指数
0
解决办法
979
查看次数

如何使用NSNotificationCenter在类之间传递对象 - 无法传递对象

我的代码:

NSDictionary *dict = @{@"1": @"_infoView3",
                       @"2": [NSNumber numberWithFloat:_showSelectionView.frame.size.height]
                       };

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(keyboardWillShow:)
                                             name:@"UIKeyboardWillShowNotification"
                                           object:dict];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(keyboardDidHide:)
                                             name:@"UIKeyboardDidHideNotification"
                                           object:dict];
Run Code Online (Sandbox Code Playgroud)

并且:

- (void) keyboardWillShow:(NSNotification *)note {
    NSDictionary *userInfo = [note userInfo];
    CGSize kbSize = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;

    // move the view up by 30 pts
    CGRect frame = self.view.frame;
    frame.origin.y = -kbSize.height;

    [UIView animateWithDuration:0.3 animations:^{
        self.view.frame = frame;
    }];
}

- (void) keyboardDidHide:(NSNotification *)note {

    // move the view back to the origin
    CGRect frame = self.view.frame;
    frame.origin.y …
Run Code Online (Sandbox Code Playgroud)

objective-c nsnotificationcenter ios

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

dataWithBytesNoCopy和dataWithBytes之间的区别?

有什么区别

+ (instancetype)dataWithBytes:(const void *)bytes length:(NSUInteger)length;

+ (instancetype)dataWithBytesNoCopy:(void *)bytes length:(NSUInteger)length;

也,

+ (instancetype)dataWithBytesNoCopy:(void *)bytes length:(NSUInteger)length freeWhenDone:(BOOL)b;

if b == YES,转换成数据后会自动释放字节吗?

我正在开发一个应用程序,几乎完成了它.但最后一个问题是它在设备上运行时因内存错误而崩溃.它只在设备上崩溃,但在模拟器中它是完美的.

"malloc: * error for object 0x17415d0c0: Invalid pointer dequeued from free list * set a breakpoint in malloc_error_break to debug";
Run Code Online (Sandbox Code Playgroud)

我已经在这个问题上工作了好几天: iOS - 我的应用程序崩溃了内存错误,如果只在Device上运行

但最后我发现问题,在我的加密和解密功能中,我有这个:

Byte *buffer    = (Byte*)malloc(asciiDataLength);
Run Code Online (Sandbox Code Playgroud)

在我使用缓冲区处理后,我将其转换为NSData:

NSData *plainData = [NSData dataWithBytesNoCopy:buffer length:asciiDataLength freeWhenDone:YES];
Run Code Online (Sandbox Code Playgroud)

此代码导致我的应用程序不断崩溃,我将其更改为

NSData *plainData = [NSData dataWithBytes:buffer length:asciiDataLength];
free(buffer);
Run Code Online (Sandbox Code Playgroud)

然后我的应用程序再也不会崩溃

所以,我必须自己解除Byte,ARC不会为我释放它.

byte nsdata ios

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